Search in sources :

Example 11 with DirectoryProperty

use of org.apache.poi.poifs.property.DirectoryProperty in project poi by apache.

the class TestDirectoryNode method testEmptyConstructor.

/**
     * test trivial constructor (a DirectoryNode with no children)
     */
public void testEmptyConstructor() {
    POIFSFileSystem fs = new POIFSFileSystem();
    DirectoryProperty property1 = new DirectoryProperty("parent");
    DirectoryProperty property2 = new DirectoryProperty("child");
    DirectoryNode parent = new DirectoryNode(property1, fs, null);
    DirectoryNode node = new DirectoryNode(property2, fs, parent);
    assertEquals(0, parent.getPath().length());
    assertEquals(1, node.getPath().length());
    assertEquals("child", node.getPath().getComponent(0));
    // verify that getEntries behaves correctly
    int count = 0;
    Iterator<Entry> iter = node.getEntries();
    while (iter.hasNext()) {
        count++;
        iter.next();
    }
    assertEquals(0, count);
    // verify behavior of isEmpty
    assertTrue(node.isEmpty());
    // verify behavior of getEntryCount
    assertEquals(0, node.getEntryCount());
    // verify behavior of getEntry
    try {
        node.getEntry("foo");
        fail("should have caught FileNotFoundException");
    } catch (FileNotFoundException ignored) {
    // as expected
    }
    // verify behavior of isDirectoryEntry
    assertTrue(node.isDirectoryEntry());
    // verify behavior of getName
    assertEquals(property2.getName(), node.getName());
    // verify behavior of isDocumentEntry
    assertTrue(!node.isDocumentEntry());
    // verify behavior of getParent
    assertEquals(parent, node.getParent());
}
Also used : DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DirectoryProperty (org.apache.poi.poifs.property.DirectoryProperty)11 DocumentProperty (org.apache.poi.poifs.property.DocumentProperty)4 Property (org.apache.poi.poifs.property.Property)4 FileNotFoundException (java.io.FileNotFoundException)2 RawDataBlock (org.apache.poi.poifs.storage.RawDataBlock)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)1 OPOIFSDocument (org.apache.poi.poifs.filesystem.OPOIFSDocument)1 POIFSDocumentPath (org.apache.poi.poifs.filesystem.POIFSDocumentPath)1 RootProperty (org.apache.poi.poifs.property.RootProperty)1