This is an automated email from the ASF dual-hosted git repository. tallison pushed a commit to branch branch_1x in repository https://gitbox.apache.org/repos/asf/tika.git
commit b7e53e45eda1dceb92b869b6f9bb37a889ddf0ed 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 5eea587..f06d192 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 @@ -394,10 +394,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
