01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.poifs.filesystem;
19:
20: import java.io.*;
21:
22: import junit.framework.*;
23:
24: import org.apache.poi.poifs.property.DirectoryProperty;
25: import org.apache.poi.poifs.property.DocumentProperty;
26: import org.apache.poi.poifs.storage.RawDataBlock;
27:
28: /**
29: * Class to test DocumentNode functionality
30: *
31: * @author Marc Johnson
32: */
33:
34: public class TestDocumentNode extends TestCase {
35:
36: /**
37: * Constructor TestDocumentNode
38: *
39: * @param name
40: */
41:
42: public TestDocumentNode(String name) {
43: super (name);
44: }
45:
46: /**
47: * test constructor
48: *
49: * @exception IOException
50: */
51:
52: public void testConstructor() throws IOException {
53: DirectoryProperty property1 = new DirectoryProperty("directory");
54: RawDataBlock[] rawBlocks = new RawDataBlock[4];
55: ByteArrayInputStream stream = new ByteArrayInputStream(
56: new byte[2048]);
57:
58: for (int j = 0; j < 4; j++) {
59: rawBlocks[j] = new RawDataBlock(stream);
60: }
61: POIFSDocument document = new POIFSDocument("document",
62: rawBlocks, 2000);
63: DocumentProperty property2 = document.getDocumentProperty();
64: DirectoryNode parent = new DirectoryNode(property1, null, null);
65: DocumentNode node = new DocumentNode(property2, parent);
66:
67: // verify we can retrieve the document
68: assertEquals(property2.getDocument(), node.getDocument());
69:
70: // verify we can get the size
71: assertEquals(property2.getSize(), node.getSize());
72:
73: // verify isDocumentEntry returns true
74: assertTrue(node.isDocumentEntry());
75:
76: // verify isDirectoryEntry returns false
77: assertTrue(!node.isDirectoryEntry());
78:
79: // verify getName behaves correctly
80: assertEquals(property2.getName(), node.getName());
81:
82: // verify getParent behaves correctly
83: assertEquals(parent, node.getParent());
84: }
85:
86: /**
87: * main method to run the unit tests
88: *
89: * @param ignored_args
90: */
91:
92: public static void main(String[] ignored_args) {
93: System.out
94: .println("Testing org.apache.poi.poifs.filesystem.DocumentNode");
95: junit.textui.TestRunner.run(TestDocumentNode.class);
96: }
97: }
|