From 3c4643af9ec8c425fde7756c9514cf7362419737 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 16 Jul 2021 08:28:44 +0000 Subject: [PATCH] try to fix integration tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891579 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/stress/HPSFFileHandler.java | 10 +----- .../org/apache/poi/stress/OPCFileHandler.java | 11 ++---- .../apache/poi/stress/StressTestUtils.java | 33 ++++++++++++++++++ .../org/apache/poi/stress/TestAllFiles.java | 9 ++--- .../apache/poi/stress/XWPFFileHandler.java | 11 ++---- .../src/test/java9/module-info.class | Bin 491 -> 492 bytes 6 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java diff --git a/poi-integration/src/test/java/org/apache/poi/stress/HPSFFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/HPSFFileHandler.java index dadb2a2d5c..3caf166f31 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/HPSFFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/HPSFFileHandler.java @@ -27,9 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; @@ -49,7 +46,7 @@ class HPSFFileHandler extends POIFSFileHandler { private static final ThreadLocal copyOutput = ThreadLocal.withInitial(HPSFFileHandler::getTempFile); - static final Set EXCLUDES_HANDLE_ADD = unmodifiableHashSet( + static final Set EXCLUDES_HANDLE_ADD = StressTestUtils.unmodifiableHashSet( "spreadsheet/45290.xls", "spreadsheet/46904.xls", "spreadsheet/55982.xls", @@ -59,11 +56,6 @@ class HPSFFileHandler extends POIFSFileHandler { "document/word2.doc" ); - private static Set unmodifiableHashSet(String... a) { - return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); - } - - @Override public void handleFile(InputStream stream, String path) throws Exception { POIFSFileSystem poifs = new POIFSFileSystem(stream); diff --git a/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java index 5408e2b437..3b55861325 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/OPCFileHandler.java @@ -23,9 +23,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.PushbackInputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.apache.poi.openxml4j.opc.ContentTypes; @@ -35,7 +32,7 @@ import org.apache.poi.xwpf.usermodel.XWPFRelation; import org.junit.jupiter.api.Test; class OPCFileHandler extends AbstractFileHandler { - private static final Set EXPECTED_FAILURES = unmodifiableHashSet( + private static final Set EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( "document/truncated62886.docx" ); @@ -44,7 +41,7 @@ class OPCFileHandler extends AbstractFileHandler { // ignore password protected files if (POIXMLDocumentHandler.isEncrypted(stream)) return; - if (EXPECTED_FAILURES.contains(path)) return; + if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return; OPCPackage p = OPCPackage.open(stream); @@ -80,8 +77,4 @@ class OPCFileHandler extends AbstractFileHandler { handleExtracting(file); } - - private static Set unmodifiableHashSet(String... a) { - return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); - } } diff --git a/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java b/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java new file mode 100644 index 0000000000..4d34326d23 --- /dev/null +++ b/poi-integration/src/test/java/org/apache/poi/stress/StressTestUtils.java @@ -0,0 +1,33 @@ +/* ==================================================================== + 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.poi.stress; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class StressTestUtils { + static Set unmodifiableHashSet(String... a) { + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); + } + + static boolean excludeFile(String path, Set excludeSet) { + String modifiedPath = path.replace('\\', '/'); + return excludeSet.contains(modifiedPath); + } +} diff --git a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java index 17e52e413c..e90cdbd810 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java @@ -16,7 +16,6 @@ ==================================================================== */ package org.apache.poi.stress; - import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -78,7 +77,7 @@ public class TestAllFiles { "**/.git/**", }; - private static final Set EXPECTED_FAILURES = unmodifiableHashSet( + private static final Set EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( "document/truncated62886.docx" ); @@ -118,7 +117,7 @@ public class TestAllFiles { @ParameterizedTest(name = "#{index} {0} {1}") @MethodSource("extractFiles") void handleExtracting(String file, FileHandlerKnown handler, String password, Class exClass, String exMessage) throws IOException { - if (EXPECTED_FAILURES.contains(file)) return; + if (StressTestUtils.excludeFile(file, EXPECTED_FAILURES)) return; System.out.println("Running extractFiles on "+file); FileHandler fileHandler = handler.fileHandler.get(); @@ -203,8 +202,4 @@ public class TestAllFiles { return msg; } - - private static Set unmodifiableHashSet(String... a) { - return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); - } } diff --git a/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java b/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java index 1c94cd3536..b61128f63f 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/XWPFFileHandler.java @@ -20,9 +20,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import org.apache.poi.ooxml.POIXMLException; @@ -30,7 +27,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.junit.jupiter.api.Test; class XWPFFileHandler extends AbstractFileHandler { - private static final Set EXPECTED_FAILURES = unmodifiableHashSet( + private static final Set EXPECTED_FAILURES = StressTestUtils.unmodifiableHashSet( "document/truncated62886.docx" ); @@ -39,7 +36,7 @@ class XWPFFileHandler extends AbstractFileHandler { // ignore password protected files if (POIXMLDocumentHandler.isEncrypted(stream)) return; - if (EXPECTED_FAILURES.contains(path)) return; + if (StressTestUtils.excludeFile(path, EXPECTED_FAILURES)) return; try (XWPFDocument doc = new XWPFDocument(stream)) { new POIXMLDocumentHandler().handlePOIXMLDocument(doc); @@ -62,8 +59,4 @@ class XWPFFileHandler extends AbstractFileHandler { handleExtracting(file); } - - private static Set unmodifiableHashSet(String... a) { - return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(a))); - } } \ No newline at end of file diff --git a/poi-integration/src/test/java9/module-info.class b/poi-integration/src/test/java9/module-info.class index 8703347af74a1293f160965d1bee953f04aaa045..e5d258d7ee61ab6f1b19d787ec22def8cf10d85f 100644 GIT binary patch literal 492 zcmY*WTT;R>6g@$CgQ5XJe6Ruobzt0qfBNGJLK|vo+jQF0kw4buhYN5~j<*G8YG!io z$$gxA@8tXE^9#TVvnDu0=f&iys~&Zz7zUB?@=)FBcwazf+#I`#$GWpF4D@>p9Dxd0U2F z*~wGcn>7i;tkTRiQDovwxF!shYc=sD!?==BjI2Inl!S_;i)H5fW#$x_|1C2uD)!SP zp|l&5MxMywOLXf1 literal 491 zcmY*WTT;R>6g?N^4T=T?@xclV!oau#|MbTdgf`UFw&}E~BY&*R4;SE~9McwOYG!gD zx#ymHl6?PsegRlx)!0cy{ zGThH%Wn^OKC_;VBANYdd{J``d5{pEHcK(pikEG$7ospZ&b$1LGgkB-ZmFb(&F~fu~ ztB7%Q80skHjt&Cp7-i!X!;~