Add Excel95 import test and improve other importer tests (#2844)

No issue.
- we don't support Excel95, but make sure that it generates an exception
- move the test data file into the appropriate directory
- for any normal test, consider exceptions a failure
This commit is contained in:
Tom Morris 2020-06-30 02:20:56 -04:00 committed by GitHub
parent 421974cc3d
commit 0f3a6006f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 5 deletions

View File

@ -209,6 +209,18 @@ public class ExcelImporterTests extends ImporterTest {
verify(options, times(1)).get("storeBlankCellsAsNulls"); verify(options, times(1)).get("storeBlankCellsAsNulls");
} }
@Test
public void readExcel95() throws FileNotFoundException, IOException{
InputStream stream = ClassLoader.getSystemResourceAsStream("excel95.xls");
try {
// We don't support Excel 95, but make sure we get an exception back
Assert.assertEquals(parseOneFileAndReturnExceptions(SUT, stream).size(), 1);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test @Test
public void readMultiSheetXls() throws FileNotFoundException, IOException{ public void readMultiSheetXls() throws FileNotFoundException, IOException{

View File

@ -27,6 +27,7 @@
package com.google.refine.importers; package com.google.refine.importers;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -85,6 +86,7 @@ public abstract class ImporterTest extends RefineTest {
} }
protected void parseOneFile(ImportingParserBase parser, Reader reader) { protected void parseOneFile(ImportingParserBase parser, Reader reader) {
List<Exception> exceptions = new ArrayList<Exception>();
parser.parseOneFile( parser.parseOneFile(
project, project,
metadata, metadata,
@ -94,12 +96,14 @@ public abstract class ImporterTest extends RefineTest {
reader, reader,
-1, -1,
options, options,
new ArrayList<Exception>() exceptions
); );
assertEquals(exceptions.size(), 0);
project.update(); project.update();
} }
protected void parseOneFile(ImportingParserBase parser, InputStream inputStream) { protected void parseOneFile(ImportingParserBase parser, InputStream inputStream) {
List<Exception> exceptions = new ArrayList<Exception>();
parser.parseOneFile( parser.parseOneFile(
project, project,
metadata, metadata,
@ -109,13 +113,32 @@ public abstract class ImporterTest extends RefineTest {
inputStream, inputStream,
-1, -1,
options, options,
new ArrayList<Exception>() exceptions
);
assertEquals(exceptions.size(), 0);
project.update();
}
protected List<Exception> parseOneFileAndReturnExceptions(ImportingParserBase parser, InputStream inputStream) {
List<Exception> exceptions = new ArrayList<Exception>();
parser.parseOneFile(
project,
metadata,
job,
"file-source",
"archive-file",
inputStream,
-1,
options,
exceptions
); );
project.update(); project.update();
return exceptions;
} }
protected void parseOneFile(TreeImportingParserBase parser, Reader reader) { protected void parseOneFile(TreeImportingParserBase parser, Reader reader) {
ImportColumnGroup rootColumnGroup = new ImportColumnGroup(); ImportColumnGroup rootColumnGroup = new ImportColumnGroup();
List<Exception> exceptions = new ArrayList<Exception>();
parser.parseOneFile( parser.parseOneFile(
project, project,
metadata, metadata,
@ -126,8 +149,9 @@ public abstract class ImporterTest extends RefineTest {
rootColumnGroup, rootColumnGroup,
-1, -1,
options, options,
new ArrayList<Exception>() exceptions
); );
assertEquals(exceptions.size(), 0);
XmlImportUtilities.createColumnsFromImport(project, rootColumnGroup); XmlImportUtilities.createColumnsFromImport(project, rootColumnGroup);
project.columnModel.update(); project.columnModel.update();
} }
@ -192,5 +216,6 @@ public abstract class ImporterTest extends RefineTest {
for (Exception e : exceptions) { for (Exception e : exceptions) {
e.printStackTrace(); e.printStackTrace();
} }
assertEquals(exceptions.size(), 0);
} }
} }