KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > filesystem > TestDocumentNode


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
19 package org.apache.poi.poifs.filesystem;
20
21 import java.io.*;
22
23 import junit.framework.*;
24
25 import org.apache.poi.poifs.property.DirectoryProperty;
26 import org.apache.poi.poifs.property.DocumentProperty;
27 import org.apache.poi.poifs.storage.RawDataBlock;
28
29 /**
30  * Class to test DocumentNode functionality
31  *
32  * @author Marc Johnson
33  */

34
35 public class TestDocumentNode
36     extends TestCase
37 {
38
39     /**
40      * Constructor TestDocumentNode
41      *
42      * @param name
43      */

44
45     public TestDocumentNode(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     /**
51      * test constructor
52      *
53      * @exception IOException
54      */

55
56     public void testConstructor()
57         throws IOException
58     {
59         DirectoryProperty property1 = new DirectoryProperty("directory");
60         RawDataBlock[] rawBlocks = new RawDataBlock[ 4 ];
61         ByteArrayInputStream stream =
62             new ByteArrayInputStream(new byte[ 2048 ]);
63
64         for (int j = 0; j < 4; j++)
65         {
66             rawBlocks[ j ] = new RawDataBlock(stream);
67         }
68         POIFSDocument document = new POIFSDocument("document", rawBlocks,
69                                          2000);
70         DocumentProperty property2 = document.getDocumentProperty();
71         DirectoryNode parent = new DirectoryNode(property1, null, null);
72         DocumentNode node = new DocumentNode(property2, parent);
73
74         // verify we can retrieve the document
75
assertEquals(property2.getDocument(), node.getDocument());
76
77         // verify we can get the size
78
assertEquals(property2.getSize(), node.getSize());
79
80         // verify isDocumentEntry returns true
81
assertTrue(node.isDocumentEntry());
82
83         // verify isDirectoryEntry returns false
84
assertTrue(!node.isDirectoryEntry());
85
86         // verify getName behaves correctly
87
assertEquals(property2.getName(), node.getName());
88
89         // verify getParent behaves correctly
90
assertEquals(parent, node.getParent());
91     }
92
93     /**
94      * main method to run the unit tests
95      *
96      * @param ignored_args
97      */

98
99     public static void main(String JavaDoc [] ignored_args)
100     {
101         System.out
102             .println("Testing org.apache.poi.poifs.filesystem.DocumentNode");
103         junit.textui.TestRunner.run(TestDocumentNode.class);
104     }
105 }
106
Popular Tags