Source Code Cross Referenced for TestModelFactory.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » eventmodel » 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.hssf.eventmodel 
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.hssf.eventmodel;
019:
020:        import java.io.ByteArrayInputStream;
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.InputStream;
023:        import java.util.ArrayList;
024:        import java.util.Iterator;
025:        import java.util.List;
026:
027:        import org.apache.poi.hssf.model.Model;
028:        import org.apache.poi.hssf.model.Sheet;
029:        import org.apache.poi.hssf.model.Workbook;
030:        import org.apache.poi.hssf.usermodel.HSSFCell;
031:        import org.apache.poi.hssf.usermodel.HSSFRow;
032:        import org.apache.poi.hssf.usermodel.HSSFSheet;
033:        import org.apache.poi.hssf.usermodel.HSSFWorkbook;
034:        import org.apache.poi.poifs.filesystem.POIFSFileSystem;
035:
036:        import junit.framework.TestCase;
037:
038:        /**
039:         * Tests the ModelFactory.  
040:         * 
041:         * @author Andrew C. Oliver acoliver@apache.org
042:         */
043:        public class TestModelFactory extends TestCase {
044:            private ModelFactory factory;
045:            private HSSFWorkbook book;
046:            private InputStream in;
047:            private List models;
048:
049:            /**
050:             * Tests that the listeners collection is created
051:             * @param arg0
052:             */
053:            public TestModelFactory(String arg0) {
054:                super (arg0);
055:                ModelFactory mf = new ModelFactory();
056:                assertTrue("listeners member cannot be null",
057:                        mf.listeners != null);
058:                assertTrue("listeners member must be a List",
059:                        mf.listeners instanceof  List);
060:            }
061:
062:            public static void main(String[] args) {
063:                junit.textui.TestRunner.run(TestModelFactory.class);
064:            }
065:
066:            protected void setUp() throws Exception {
067:                super .setUp();
068:                models = new ArrayList(3);
069:                factory = new ModelFactory();
070:                book = new HSSFWorkbook();
071:                ByteArrayOutputStream stream = (ByteArrayOutputStream) setupRunFile(book);
072:                POIFSFileSystem fs = new POIFSFileSystem(
073:                        new ByteArrayInputStream(stream.toByteArray()));
074:                in = fs.createDocumentInputStream("Workbook");
075:            }
076:
077:            protected void tearDown() throws Exception {
078:                super .tearDown();
079:                factory = null;
080:                book = null;
081:                in = null;
082:            }
083:
084:            /**
085:             * tests that listeners can be registered
086:             */
087:            public void testRegisterListener() {
088:                if (factory.listeners.size() != 0) {
089:                    factory = new ModelFactory();
090:                }
091:
092:                factory.registerListener(new MFListener(null));
093:                factory.registerListener(new MFListener(null));
094:                assertTrue("Factory listeners should be two, was="
095:                        + factory.listeners.size(),
096:                        factory.listeners.size() == 2);
097:            }
098:
099:            /**
100:             * tests that given a simple input stream with one workbook and sheet
101:             * that those models are processed and returned.
102:             */
103:            public void testRun() {
104:                Model temp = null;
105:                Iterator mi = null;
106:
107:                if (factory.listeners.size() != 0) {
108:                    factory = new ModelFactory();
109:                }
110:
111:                factory.registerListener(new MFListener(models));
112:                factory.run(in);
113:
114:                assertTrue("Models size must be 2 was = " + models.size(),
115:                        models.size() == 2);
116:                mi = models.iterator();
117:                temp = (Model) mi.next();
118:
119:                assertTrue("First model is Workbook was "
120:                        + temp.getClass().getName(), temp instanceof  Workbook);
121:
122:                temp = (Model) mi.next();
123:
124:                assertTrue("Second model is Sheet was "
125:                        + temp.getClass().getName(), temp instanceof  Sheet);
126:
127:            }
128:
129:            /**
130:             * Sets up a test file
131:             */
132:            private ByteArrayOutputStream setupRunFile(HSSFWorkbook book)
133:                    throws Exception {
134:                ByteArrayOutputStream stream = new ByteArrayOutputStream();
135:                HSSFSheet sheet = book.createSheet("Test");
136:                HSSFRow row = sheet.createRow(0);
137:                HSSFCell cell = row.createCell((short) 0);
138:                cell.setCellValue(10.5);
139:                book.write(stream);
140:                return stream;
141:            }
142:
143:        }
144:
145:        /**
146:         * listener for use in the test
147:         */
148:        class MFListener implements  ModelFactoryListener {
149:            private List mlist;
150:
151:            public MFListener(List mlist) {
152:                this .mlist = mlist;
153:            }
154:
155:            public boolean process(Model model) {
156:                mlist.add(model);
157:                return true;
158:            }
159:
160:            public Iterator models() {
161:                return mlist.iterator();
162:            }
163:
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.