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:
parent
421974cc3d
commit
0f3a6006f3
@ -209,7 +209,19 @@ public class ExcelImporterTests extends ImporterTest {
|
||||
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
|
||||
public void readMultiSheetXls() throws FileNotFoundException, IOException{
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
package com.google.refine.importers;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -85,6 +86,7 @@ public abstract class ImporterTest extends RefineTest {
|
||||
}
|
||||
|
||||
protected void parseOneFile(ImportingParserBase parser, Reader reader) {
|
||||
List<Exception> exceptions = new ArrayList<Exception>();
|
||||
parser.parseOneFile(
|
||||
project,
|
||||
metadata,
|
||||
@ -94,12 +96,14 @@ public abstract class ImporterTest extends RefineTest {
|
||||
reader,
|
||||
-1,
|
||||
options,
|
||||
new ArrayList<Exception>()
|
||||
exceptions
|
||||
);
|
||||
assertEquals(exceptions.size(), 0);
|
||||
project.update();
|
||||
}
|
||||
|
||||
protected void parseOneFile(ImportingParserBase parser, InputStream inputStream) {
|
||||
List<Exception> exceptions = new ArrayList<Exception>();
|
||||
parser.parseOneFile(
|
||||
project,
|
||||
metadata,
|
||||
@ -109,13 +113,32 @@ public abstract class ImporterTest extends RefineTest {
|
||||
inputStream,
|
||||
-1,
|
||||
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();
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
protected void parseOneFile(TreeImportingParserBase parser, Reader reader) {
|
||||
ImportColumnGroup rootColumnGroup = new ImportColumnGroup();
|
||||
List<Exception> exceptions = new ArrayList<Exception>();
|
||||
parser.parseOneFile(
|
||||
project,
|
||||
metadata,
|
||||
@ -126,8 +149,9 @@ public abstract class ImporterTest extends RefineTest {
|
||||
rootColumnGroup,
|
||||
-1,
|
||||
options,
|
||||
new ArrayList<Exception>()
|
||||
exceptions
|
||||
);
|
||||
assertEquals(exceptions.size(), 0);
|
||||
XmlImportUtilities.createColumnsFromImport(project, rootColumnGroup);
|
||||
project.columnModel.update();
|
||||
}
|
||||
@ -192,5 +216,6 @@ public abstract class ImporterTest extends RefineTest {
|
||||
for (Exception e : exceptions) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assertEquals(exceptions.size(), 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user