Source Code Cross Referenced for TestDirectoryNode.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » poifs » filesystem » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.poifs.filesystem 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         Licensed to the Apache Software Foundation (ASF) under one or more
003:         contributor license agreements.  See the NOTICE file distributed with
004:         this work for additional information regarding copyright ownership.
005:         The ASF licenses this file to You under the Apache License, Version 2.0
006:         (the "License"); you may not use this file except in compliance with
007:         the License.  You may obtain a copy of the License at
008:
009:         http://www.apache.org/licenses/LICENSE-2.0
010:
011:         Unless required by applicable law or agreed to in writing, software
012:         distributed under the License is distributed on an "AS IS" BASIS,
013:         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         See the License for the specific language governing permissions and
015:         limitations under the License.
016:         ==================================================================== */
017:
018:        package org.apache.poi.poifs.filesystem;
019:
020:        import java.io.*;
021:
022:        import java.util.*;
023:
024:        import junit.framework.*;
025:
026:        import org.apache.poi.poifs.property.DirectoryProperty;
027:        import org.apache.poi.poifs.property.DocumentProperty;
028:
029:        /**
030:         * Class to test DirectoryNode functionality
031:         *
032:         * @author Marc Johnson
033:         */
034:
035:        public class TestDirectoryNode extends TestCase {
036:
037:            /**
038:             * Constructor TestDirectoryNode
039:             *
040:             * @param name
041:             */
042:
043:            public TestDirectoryNode(String name) {
044:                super (name);
045:            }
046:
047:            /**
048:             * test trivial constructor (a DirectoryNode with no children)
049:             *
050:             * @exception IOException
051:             */
052:
053:            public void testEmptyConstructor() throws IOException {
054:                POIFSFileSystem fs = new POIFSFileSystem();
055:                DirectoryProperty property1 = new DirectoryProperty("parent");
056:                DirectoryProperty property2 = new DirectoryProperty("child");
057:                DirectoryNode parent = new DirectoryNode(property1, fs, null);
058:                DirectoryNode node = new DirectoryNode(property2, fs, parent);
059:
060:                assertEquals(0, parent.getPath().length());
061:                assertEquals(1, node.getPath().length());
062:                assertEquals("child", node.getPath().getComponent(0));
063:
064:                // verify that getEntries behaves correctly
065:                int count = 0;
066:                Iterator iter = node.getEntries();
067:
068:                while (iter.hasNext()) {
069:                    count++;
070:                    iter.next();
071:                }
072:                assertEquals(0, count);
073:
074:                // verify behavior of isEmpty
075:                assertTrue(node.isEmpty());
076:
077:                // verify behavior of getEntryCount
078:                assertEquals(0, node.getEntryCount());
079:
080:                // verify behavior of getEntry
081:                try {
082:                    node.getEntry("foo");
083:                    fail("should have caught FileNotFoundException");
084:                } catch (FileNotFoundException ignored) {
085:
086:                    // as expected
087:                }
088:
089:                // verify behavior of isDirectoryEntry
090:                assertTrue(node.isDirectoryEntry());
091:
092:                // verify behavior of getName
093:                assertEquals(property2.getName(), node.getName());
094:
095:                // verify behavior of isDocumentEntry
096:                assertTrue(!node.isDocumentEntry());
097:
098:                // verify behavior of getParent
099:                assertEquals(parent, node.getParent());
100:            }
101:
102:            /**
103:             * test non-trivial constructor (a DirectoryNode with children)
104:             *
105:             * @exception IOException
106:             */
107:
108:            public void testNonEmptyConstructor() throws IOException {
109:                DirectoryProperty property1 = new DirectoryProperty("parent");
110:                DirectoryProperty property2 = new DirectoryProperty("child1");
111:
112:                property1.addChild(property2);
113:                property1.addChild(new DocumentProperty("child2", 2000));
114:                property2.addChild(new DocumentProperty("child3", 30000));
115:                DirectoryNode node = new DirectoryNode(property1,
116:                        new POIFSFileSystem(), null);
117:
118:                // verify that getEntries behaves correctly
119:                int count = 0;
120:                Iterator iter = node.getEntries();
121:
122:                while (iter.hasNext()) {
123:                    count++;
124:                    iter.next();
125:                }
126:                assertEquals(2, count);
127:
128:                // verify behavior of isEmpty
129:                assertTrue(!node.isEmpty());
130:
131:                // verify behavior of getEntryCount
132:                assertEquals(2, node.getEntryCount());
133:
134:                // verify behavior of getEntry
135:                DirectoryNode child1 = (DirectoryNode) node.getEntry("child1");
136:
137:                child1.getEntry("child3");
138:                node.getEntry("child2");
139:                try {
140:                    node.getEntry("child3");
141:                    fail("should have caught FileNotFoundException");
142:                } catch (FileNotFoundException ignored) {
143:
144:                    // as expected
145:                }
146:
147:                // verify behavior of isDirectoryEntry
148:                assertTrue(node.isDirectoryEntry());
149:
150:                // verify behavior of getName
151:                assertEquals(property1.getName(), node.getName());
152:
153:                // verify behavior of isDocumentEntry
154:                assertTrue(!node.isDocumentEntry());
155:
156:                // verify behavior of getParent
157:                assertNull(node.getParent());
158:            }
159:
160:            /**
161:             * test deletion methods
162:             *
163:             * @exception IOException
164:             */
165:
166:            public void testDeletion() throws IOException {
167:                POIFSFileSystem fs = new POIFSFileSystem();
168:                DirectoryEntry root = fs.getRoot();
169:
170:                // verify cannot delete the root directory
171:                assertTrue(!root.delete());
172:                DirectoryEntry dir = fs.createDirectory("myDir");
173:
174:                assertTrue(!root.isEmpty());
175:
176:                // verify can delete empty directory
177:                assertTrue(dir.delete());
178:                dir = fs.createDirectory("NextDir");
179:                DocumentEntry doc = dir.createDocument("foo",
180:                        new ByteArrayInputStream(new byte[1]));
181:
182:                assertTrue(!dir.isEmpty());
183:
184:                // verify cannot delete empty directory
185:                assertTrue(!dir.delete());
186:                assertTrue(doc.delete());
187:
188:                // verify now we can delete it
189:                assertTrue(dir.delete());
190:                assertTrue(root.isEmpty());
191:            }
192:
193:            /**
194:             * test change name methods
195:             *
196:             * @exception IOException
197:             */
198:
199:            public void testRename() throws IOException {
200:                POIFSFileSystem fs = new POIFSFileSystem();
201:                DirectoryEntry root = fs.getRoot();
202:
203:                // verify cannot rename the root directory
204:                assertTrue(!root.renameTo("foo"));
205:                DirectoryEntry dir = fs.createDirectory("myDir");
206:
207:                assertTrue(dir.renameTo("foo"));
208:                assertEquals("foo", dir.getName());
209:                DirectoryEntry dir2 = fs.createDirectory("myDir");
210:
211:                assertTrue(!dir2.renameTo("foo"));
212:                assertEquals("myDir", dir2.getName());
213:                assertTrue(dir.renameTo("FirstDir"));
214:                assertTrue(dir2.renameTo("foo"));
215:                assertEquals("foo", dir2.getName());
216:            }
217:
218:            /**
219:             * main method to run the unit tests
220:             *
221:             * @param ignored_args
222:             */
223:
224:            public static void main(String[] ignored_args) {
225:                System.out
226:                        .println("Testing org.apache.poi.poifs.filesystem.DirectoryNode");
227:                junit.textui.TestRunner.run(TestDirectoryNode.class);
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.