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;
|
|
|
|
|
|
2013-10-27 08:16:29 +00:00
|
|
|
import static org.junit.Assert.assertNotNull;
|
2020-08-18 13:50:31 +00:00
|
|
|
import static org.junit.Assert.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;
|
2013-10-25 21:57:48 +00:00
|
|
|
|
2014-02-15 00:20:24 +00:00
|
|
|
import org.apache.poi.POIDataSamples;
|
2013-10-25 21:57:48 +00:00
|
|
|
import org.junit.Test;
|
2015-08-25 08:30:49 +00:00
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Parameterized;
|
|
|
|
|
import org.junit.runners.Parameterized.Parameter;
|
|
|
|
|
import org.junit.runners.Parameterized.Parameters;
|
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
|
|
|
*
|
2015-08-25 08:30:49 +00:00
|
|
|
* This test uses {@link Parameterized} to run the test for each file separatedely.
|
2013-10-25 21:57:48 +00:00
|
|
|
*/
|
2015-08-25 08:30:49 +00:00
|
|
|
@RunWith(Parameterized.class)
|
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
|
|
|
|
2015-08-27 06:32:33 +00:00
|
|
|
@Parameters(name="{index}: {0}")
|
2015-08-25 08:30:49 +00:00
|
|
|
public static Iterable<Object[]> files() {
|
|
|
|
|
String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
|
|
|
|
|
if(dataDirName == null) {
|
|
|
|
|
dataDirName = "test-data";
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-16 08:27:23 +00:00
|
|
|
List<Object[]> 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
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
return files;
|
|
|
|
|
}
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
private static void findFile(List<Object[]> 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-07-22 22:08:33 +00:00
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
assertNotNull("Did not find any xls files in directory " + dir, files);
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
for(String file : files) {
|
2020-08-17 20:25:08 +00:00
|
|
|
list.add(new Object[]{new File(dir, file)});
|
|
|
|
|
}
|
2015-08-25 08:30:49 +00:00
|
|
|
}
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2015-08-25 08:30:49 +00:00
|
|
|
@Parameter
|
|
|
|
|
public File file;
|
2020-07-22 22:08:33 +00:00
|
|
|
|
2013-10-25 21:57:48 +00:00
|
|
|
@Test
|
|
|
|
|
public void testMain() 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
|
|
|
}
|