Fix testcases which were not executed before, use tempfile, cleanup, ...
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647511 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7ee9ce8388
commit
95c9b9991a
@ -285,43 +285,56 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void incrementSheetId() {
|
public void incrementSheetId() throws IOException {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
int sheetId = (int)wb.createSheet().sheet.getSheetId();
|
try {
|
||||||
assertEquals(1, sheetId);
|
int sheetId = (int)wb.createSheet().sheet.getSheetId();
|
||||||
sheetId = (int)wb.createSheet().sheet.getSheetId();
|
assertEquals(1, sheetId);
|
||||||
assertEquals(2, sheetId);
|
sheetId = (int)wb.createSheet().sheet.getSheetId();
|
||||||
|
assertEquals(2, sheetId);
|
||||||
|
|
||||||
//test file with gaps in the sheetId sequence
|
//test file with gaps in the sheetId sequence
|
||||||
wb = XSSFTestDataSamples.openSampleWorkbook("47089.xlsm");
|
XSSFWorkbook wbBack = XSSFTestDataSamples.openSampleWorkbook("47089.xlsm");
|
||||||
int lastSheetId = (int)wb.getSheetAt(wb.getNumberOfSheets() - 1).sheet.getSheetId();
|
try {
|
||||||
sheetId = (int)wb.createSheet().sheet.getSheetId();
|
int lastSheetId = (int)wbBack.getSheetAt(wbBack.getNumberOfSheets() - 1).sheet.getSheetId();
|
||||||
assertEquals(lastSheetId+1, sheetId);
|
sheetId = (int)wbBack.createSheet().sheet.getSheetId();
|
||||||
|
assertEquals(lastSheetId+1, sheetId);
|
||||||
|
} finally {
|
||||||
|
wbBack.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test setting of core properties such as Title and Author
|
* Test setting of core properties such as Title and Author
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void workbookProperties() {
|
public void workbookProperties() throws IOException {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
POIXMLProperties props = workbook.getProperties();
|
try {
|
||||||
assertNotNull(props);
|
POIXMLProperties props = workbook.getProperties();
|
||||||
//the Application property must be set for new workbooks, see Bugzilla #47559
|
assertNotNull(props);
|
||||||
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
//the Application property must be set for new workbooks, see Bugzilla #47559
|
||||||
|
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
|
|
||||||
PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
|
PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
|
||||||
assertNotNull(opcProps);
|
assertNotNull(opcProps);
|
||||||
|
|
||||||
opcProps.setTitleProperty("Testing Bugzilla #47460");
|
opcProps.setTitleProperty("Testing Bugzilla #47460");
|
||||||
assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
|
assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
|
||||||
opcProps.setCreatorProperty("poi-dev@poi.apache.org");
|
opcProps.setCreatorProperty("poi-dev@poi.apache.org");
|
||||||
|
|
||||||
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
|
XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook);
|
||||||
assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Apache POI", wbBack.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
|
opcProps = wbBack.getProperties().getCoreProperties().getUnderlyingProperties();
|
||||||
assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
|
assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
|
||||||
assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
|
assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
|
||||||
|
} finally {
|
||||||
|
workbook.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -770,33 +783,56 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadWorkbookWithPivotTable() throws Exception {
|
public void testLoadWorkbookWithPivotTable() throws Exception {
|
||||||
String fileName = "ooxml-pivottable.xlsx";
|
File file = TempFile.createTempFile("ooxml-pivottable", ".xlsx");
|
||||||
|
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
setPivotData(wb);
|
try {
|
||||||
|
setPivotData(wb);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(fileName);
|
FileOutputStream fileOut = new FileOutputStream(file);
|
||||||
wb.write(fileOut);
|
wb.write(fileOut);
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
} finally {
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
|
|
||||||
XSSFWorkbook wb2 = (XSSFWorkbook) WorkbookFactory.create(new File(fileName));
|
XSSFWorkbook wb2 = (XSSFWorkbook) WorkbookFactory.create(file);
|
||||||
assertTrue(wb2.getPivotTables().size() == 1);
|
try {
|
||||||
|
assertTrue(wb2.getPivotTables().size() == 1);
|
||||||
|
} finally {
|
||||||
|
wb2.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(file.delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddPivotTableToWorkbookWithLoadedPivotTable() throws Exception {
|
public void testAddPivotTableToWorkbookWithLoadedPivotTable() throws Exception {
|
||||||
String fileName = "ooxml-pivottable.xlsx";
|
File file = TempFile.createTempFile("ooxml-pivottable", ".xlsx");
|
||||||
|
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
setPivotData(wb);
|
try {
|
||||||
|
setPivotData(wb);
|
||||||
|
|
||||||
FileOutputStream fileOut = new FileOutputStream(fileName);
|
FileOutputStream fileOut = new FileOutputStream(file);
|
||||||
wb.write(fileOut);
|
try {
|
||||||
fileOut.close();
|
wb.write(fileOut);
|
||||||
|
} finally {
|
||||||
|
fileOut.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
|
|
||||||
XSSFWorkbook wb2 = (XSSFWorkbook) WorkbookFactory.create(new File(fileName));
|
XSSFWorkbook wb2 = (XSSFWorkbook) WorkbookFactory.create(file);
|
||||||
setPivotData(wb2);
|
try {
|
||||||
assertTrue(wb2.getPivotTables().size() == 2);
|
setPivotData(wb2);
|
||||||
|
assertTrue(wb2.getPivotTables().size() == 2);
|
||||||
|
} finally {
|
||||||
|
wb2.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(file.delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user