2014-01-18 00:38:04 +00:00
|
|
|
/* ====================================================================
|
|
|
|
|
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.
|
|
|
|
|
==================================================================== */
|
2013-10-25 21:57:48 +00:00
|
|
|
package org.apache.poi.hssf.dev;
|
|
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
2013-10-25 21:57:48 +00:00
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.ArrayList;
|
2016-06-30 22:59:46 +00:00
|
|
|
import java.util.HashMap;
|
2013-10-25 21:57:48 +00:00
|
|
|
import java.util.List;
|
2015-09-01 19:06:53 +00:00
|
|
|
import java.util.Locale;
|
2016-06-30 22:59:46 +00:00
|
|
|
import java.util.Map;
|
2020-12-24 18:42:29 +00:00
|
|
|
import java.util.stream.Stream;
|
2013-10-25 21:57:48 +00:00
|
|
|
|
2014-02-15 00:20:24 +00:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2020-12-24 18:42:29 +00:00
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
2013-10-25 21:57:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class for integration-style tests which iterate over all test-files
|
|
|
|
|
* and execute the same action to find out if any change breaks these applications.
|
|
|
|
|
*/
|
2020-07-22 22:08:33 +00:00
|
|
|
public abstract class BaseTestIteratingXLS {
|
2020-08-18 13:50:31 +00:00
|
|
|
protected static final Map<String,Class<? extends Throwable>> EXCLUDED = new HashMap<>();
|
2013-10-25 21:57:48 +00:00
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
private static Stream<Arguments> files() {
|
2015-08-25 08:30:49 +00:00
|
|
|
String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
|
|
|
|
|
if(dataDirName == null) {
|
|
|
|
|
dataDirName = "test-data";
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
List<Arguments> files = new ArrayList<>();
|
2015-08-25 08:30:49 +00:00
|
|
|
findFile(files, dataDirName + "/spreadsheet");
|
|
|
|
|
findFile(files, dataDirName + "/hpsf");
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
return files.stream();
|
2015-08-25 08:30:49 +00:00
|
|
|
}
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
private static void findFile(List<Arguments> list, String dir) {
|
2018-12-26 13:28:32 +00:00
|
|
|
String[] files = new File(dir).list((arg0, arg1) -> arg1.toLowerCase(Locale.ROOT).endsWith(".xls"));
|
2020-12-24 18:42:29 +00:00
|
|
|
assertNotNull(files, "Did not find any xls files in directory " + dir);
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
for(String file : files) {
|
2020-12-24 18:42:29 +00:00
|
|
|
list.add(Arguments.of(new File(dir, file)));
|
2015-08-25 08:30:49 +00:00
|
|
|
}
|
2020-12-24 18:42:29 +00:00
|
|
|
}
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2020-12-24 18:42:29 +00:00
|
|
|
@ParameterizedTest
|
|
|
|
|
@MethodSource("files")
|
2021-01-08 23:50:02 +00:00
|
|
|
void testMain(File file) throws Exception {
|
2016-06-30 22:59:46 +00:00
|
|
|
String fileName = file.getName();
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2020-08-18 13:50:31 +00:00
|
|
|
Class<? extends Throwable> t = EXCLUDED.get(fileName);
|
|
|
|
|
|
|
|
|
|
if (t == null) {
|
|
|
|
|
runOneFile(file);
|
|
|
|
|
} else {
|
|
|
|
|
assertThrows(t, () -> runOneFile(file));
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 21:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-21 00:14:21 +00:00
|
|
|
abstract void runOneFile(File pFile) throws Exception;
|
2013-10-25 21:57:48 +00:00
|
|
|
}
|