This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 7e8d64d TIKA-3386 allow a times parameter in MockParser
new 0b9e0cf Merge remote-tracking branch 'origin/main' into main
7e8d64d is described below
commit 7e8d64d381de74178be484b4f8168410c8483860
Author: tallison <[email protected]>
AuthorDate: Wed May 5 12:38:38 2021 -0400
TIKA-3386 allow a times parameter in MockParser
---
.../org/apache/tika/parser/mock/MockParser.java | 13 ++++++++---
.../apache/tika/parser/mock/MockParserTest.java | 11 +++++++++
.../test/resources/test-documents/mock_times.xml | 26 ++++++++++++++++++++++
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git
a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
index b394c7a..14e24f5 100644
--- a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
@@ -393,10 +393,17 @@ public class MockParser extends AbstractParser {
if (eNode != null) {
elementType = eNode.getTextContent();
}
+ int times = 1;
+ Node tNode = attrs.getNamedItem("times");
+ if (tNode != null) {
+ times = Integer.parseInt(tNode.getTextContent());
+ }
String text = action.getTextContent();
- xhtml.startElement(elementType);
- xhtml.characters(text);
- xhtml.endElement(elementType);
+ for (int i = 0; i < times; i++) {
+ xhtml.startElement(elementType);
+ xhtml.characters(text);
+ xhtml.endElement(elementType);
+ }
}
diff --git
a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
index 843d737..ade8b90 100644
--- a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
@@ -16,9 +16,13 @@
*/
package org.apache.tika.parser.mock;
+import java.util.List;
+
import org.junit.Test;
import org.apache.tika.TikaTest;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
public class MockParserTest extends TikaTest {
@@ -27,4 +31,11 @@ public class MockParserTest extends TikaTest {
//just make sure there aren't any exceptions
getRecursiveMetadata("mock_fakeload.xml");
}
+
+ @Test
+ public void testTimes() throws Exception {
+ List<Metadata> metadataList = getRecursiveMetadata("mock_times.xml");
+ assertContainsCount("hello",
+ metadataList.get(0).get(TikaCoreProperties.TIKA_CONTENT), 30);
+ }
}
diff --git a/tika-core/src/test/resources/test-documents/mock_times.xml
b/tika-core/src/test/resources/test-documents/mock_times.xml
new file mode 100644
index 0000000..a309655
--- /dev/null
+++ b/tika-core/src/test/resources/test-documents/mock_times.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.
+-->
+
+<mock>
+
+ <metadata action="add" name="dc:creator">Nikolai Lobachevsky</metadata>
+ <write element="p" times="30"> hello </write>
+</mock>
\ No newline at end of file