Fix inconsistent indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1676845 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2889cabaed
commit
73aa2c9ee3
@ -31,117 +31,117 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public final class TestWorkbookFactory extends TestCase {
|
public final class TestWorkbookFactory extends TestCase {
|
||||||
private String xls;
|
private String xls;
|
||||||
private String xlsx;
|
private String xlsx;
|
||||||
private String[] xls_prot;
|
private String[] xls_prot;
|
||||||
private String[] xlsx_prot;
|
private String[] xlsx_prot;
|
||||||
private String txt;
|
private String txt;
|
||||||
|
|
||||||
protected void setUp() {
|
protected void setUp() {
|
||||||
xls = "SampleSS.xls";
|
xls = "SampleSS.xls";
|
||||||
xlsx = "SampleSS.xlsx";
|
xlsx = "SampleSS.xlsx";
|
||||||
xls_prot = new String[] {"password.xls", "password"};
|
xls_prot = new String[] {"password.xls", "password"};
|
||||||
xlsx_prot = new String[]{"protected_passtika.xlsx", "tika"};
|
xlsx_prot = new String[]{"protected_passtika.xlsx", "tika"};
|
||||||
txt = "SampleSS.txt";
|
txt = "SampleSS.txt";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateNative() throws Exception {
|
public void testCreateNative() throws Exception {
|
||||||
Workbook wb;
|
|
||||||
|
|
||||||
// POIFS -> hssf
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls))
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
|
||||||
wb.close();
|
|
||||||
|
|
||||||
// Package -> xssf
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
OPCPackage.open(
|
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx))
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
|
||||||
// TODO: this re-writes the sample-file?! wb.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the appropriate kind of Workbook, but
|
|
||||||
* checking the mime magic at the start of the
|
|
||||||
* InputStream, then creating what's required.
|
|
||||||
*/
|
|
||||||
public void testCreateGeneric() throws Exception {
|
|
||||||
Workbook wb;
|
|
||||||
|
|
||||||
// InputStream -> either
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
HSSFTestDataSamples.openSampleFileStream(xls)
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
|
||||||
wb.close();
|
|
||||||
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx)
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
|
||||||
// TODO: this re-writes the sample-file?! wb.close();
|
|
||||||
|
|
||||||
// File -> either
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
HSSFTestDataSamples.getSampleFile(xls)
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
|
||||||
wb.close();
|
|
||||||
|
|
||||||
wb = WorkbookFactory.create(
|
|
||||||
HSSFTestDataSamples.getSampleFile(xlsx)
|
|
||||||
);
|
|
||||||
assertNotNull(wb);
|
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
|
||||||
|
|
||||||
// TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle...
|
|
||||||
((XSSFWorkbook)wb).getPackage().revert();
|
|
||||||
|
|
||||||
// Invalid type -> exception
|
|
||||||
try {
|
|
||||||
InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt);
|
|
||||||
try {
|
|
||||||
wb = WorkbookFactory.create(stream);
|
|
||||||
} finally {
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
fail();
|
|
||||||
} catch(IllegalArgumentException e) {
|
|
||||||
// Good
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that the overloaded stream methods which take passwords work properly
|
|
||||||
*/
|
|
||||||
public void testCreateWithPasswordFromStream() throws Exception {
|
|
||||||
Workbook wb;
|
Workbook wb;
|
||||||
|
|
||||||
|
// POIFS -> hssf
|
||||||
// Unprotected, no password given, opens normally
|
wb = WorkbookFactory.create(
|
||||||
|
new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls))
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
|
// Package -> xssf
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
OPCPackage.open(
|
||||||
|
HSSFTestDataSamples.openSampleFileStream(xlsx))
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
// TODO: this re-writes the sample-file?! wb.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the appropriate kind of Workbook, but
|
||||||
|
* checking the mime magic at the start of the
|
||||||
|
* InputStream, then creating what's required.
|
||||||
|
*/
|
||||||
|
public void testCreateGeneric() throws Exception {
|
||||||
|
Workbook wb;
|
||||||
|
|
||||||
|
// InputStream -> either
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
HSSFTestDataSamples.openSampleFileStream(xls)
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
HSSFTestDataSamples.openSampleFileStream(xlsx)
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
// TODO: this re-writes the sample-file?! wb.close();
|
||||||
|
|
||||||
|
// File -> either
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
HSSFTestDataSamples.getSampleFile(xls)
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
|
wb.close();
|
||||||
|
|
||||||
|
wb = WorkbookFactory.create(
|
||||||
|
HSSFTestDataSamples.getSampleFile(xlsx)
|
||||||
|
);
|
||||||
|
assertNotNull(wb);
|
||||||
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
|
||||||
|
// TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle...
|
||||||
|
((XSSFWorkbook)wb).getPackage().revert();
|
||||||
|
|
||||||
|
// Invalid type -> exception
|
||||||
|
try {
|
||||||
|
InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt);
|
||||||
|
try {
|
||||||
|
wb = WorkbookFactory.create(stream);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
fail();
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
// Good
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the overloaded stream methods which take passwords work properly
|
||||||
|
*/
|
||||||
|
public void testCreateWithPasswordFromStream() throws Exception {
|
||||||
|
Workbook wb;
|
||||||
|
|
||||||
|
|
||||||
|
// Unprotected, no password given, opens normally
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xls), null
|
HSSFTestDataSamples.openSampleFileStream(xls), null
|
||||||
);
|
);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx), null
|
HSSFTestDataSamples.openSampleFileStream(xlsx), null
|
||||||
);
|
);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
|
||||||
|
|
||||||
// Unprotected, wrong password, opens normally
|
// Unprotected, wrong password, opens normally
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xls), "wrong"
|
HSSFTestDataSamples.openSampleFileStream(xls), "wrong"
|
||||||
@ -149,14 +149,14 @@ public final class TestWorkbookFactory extends TestCase {
|
|||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx), "wrong"
|
HSSFTestDataSamples.openSampleFileStream(xlsx), "wrong"
|
||||||
);
|
);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
|
||||||
|
|
||||||
// Protected, correct password, opens fine
|
// Protected, correct password, opens fine
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xls_prot[0]), xls_prot[1]
|
HSSFTestDataSamples.openSampleFileStream(xls_prot[0]), xls_prot[1]
|
||||||
@ -164,14 +164,14 @@ public final class TestWorkbookFactory extends TestCase {
|
|||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof HSSFWorkbook);
|
assertTrue(wb instanceof HSSFWorkbook);
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
HSSFTestDataSamples.openSampleFileStream(xlsx_prot[0]), xlsx_prot[1]
|
HSSFTestDataSamples.openSampleFileStream(xlsx_prot[0]), xlsx_prot[1]
|
||||||
);
|
);
|
||||||
assertNotNull(wb);
|
assertNotNull(wb);
|
||||||
assertTrue(wb instanceof XSSFWorkbook);
|
assertTrue(wb instanceof XSSFWorkbook);
|
||||||
|
|
||||||
|
|
||||||
// Protected, wrong password, throws Exception
|
// Protected, wrong password, throws Exception
|
||||||
try {
|
try {
|
||||||
wb = WorkbookFactory.create(
|
wb = WorkbookFactory.create(
|
||||||
@ -186,14 +186,14 @@ public final class TestWorkbookFactory extends TestCase {
|
|||||||
);
|
);
|
||||||
fail("Shouldn't be able to open with the wrong password");
|
fail("Shouldn't be able to open with the wrong password");
|
||||||
} catch (EncryptedDocumentException e) {}
|
} catch (EncryptedDocumentException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the overloaded file methods which take passwords work properly
|
* Check that the overloaded file methods which take passwords work properly
|
||||||
*/
|
*/
|
||||||
public void testCreateWithPasswordFromFile() throws Exception {
|
public void testCreateWithPasswordFromFile() throws Exception {
|
||||||
Workbook wb;
|
Workbook wb;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user