/**
* Test usermodel API for setting custom properties
*/
public void testCustomProperties() {
POIXMLDocument wb = new XSSFWorkbook();
POIXMLProperties.CustomProperties customProps = wb.getProperties().getCustomProperties();
customProps.addProperty("test-1", "string val");
customProps.addProperty("test-2", 1974);
customProps.addProperty("test-3", 36.6);
//adding a duplicate
try {
customProps.addProperty("test-3", 36.6);
fail("expected exception");
} catch(IllegalArgumentException e){
assertEquals("A property with this name already exists in the custom properties", e.getMessage());
}
customProps.addProperty("test-4", true);
wb = XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)wb);
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties ctProps =
wb.getProperties().getCustomProperties().getUnderlyingProperties();
assertEquals(4, ctProps.sizeOfPropertyArray());
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty p;
p = ctProps.getPropertyArray(0);
assertEquals("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", p.getFmtid());