Source Code Cross Referenced for TestMetaDataIPI.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hpsf » basic » 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.hpsf.basic 
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.hpsf.basic;
019:
020:        import java.io.ByteArrayInputStream;
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.FileNotFoundException;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.util.Date;
026:        import java.util.Random;
027:
028:        import junit.framework.TestCase;
029:
030:        import org.apache.poi.hpsf.CustomProperties;
031:        import org.apache.poi.hpsf.DocumentSummaryInformation;
032:        import org.apache.poi.hpsf.MarkUnsupportedException;
033:        import org.apache.poi.hpsf.NoPropertySetStreamException;
034:        import org.apache.poi.hpsf.PropertySet;
035:        import org.apache.poi.hpsf.PropertySetFactory;
036:        import org.apache.poi.hpsf.SummaryInformation;
037:        import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
038:        import org.apache.poi.hpsf.WritingNotSupportedException;
039:        import org.apache.poi.poifs.filesystem.DirectoryEntry;
040:        import org.apache.poi.poifs.filesystem.DocumentEntry;
041:        import org.apache.poi.poifs.filesystem.DocumentInputStream;
042:        import org.apache.poi.poifs.filesystem.POIFSFileSystem;
043:
044:        /**
045:         * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java
046:         * This class tests reading and writing of meta data. No actual document is created. All information
047:         * is stored in a virtal document in a ByteArrayOutputStream
048:         * @author Matthias Günter
049:         * @since 2006-03-03
050:         * @version $Id: TestEmptyProperties.java 353563 2004-06-22 16:16:33Z klute $
051:         */
052:        public class TestMetaDataIPI extends TestCase {
053:
054:            private ByteArrayOutputStream bout = null; //our store
055:            private POIFSFileSystem poifs = null;
056:            DirectoryEntry dir = null;
057:            DocumentSummaryInformation dsi = null;
058:            SummaryInformation si = null;
059:
060:            /**
061:             * Standard constructor
062:             * @param s
063:             */
064:            public TestMetaDataIPI(String s) {
065:                super (s);
066:            }
067:
068:            /**
069:             * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the 
070:             * SummaryInformation to reasonable values
071:             */
072:            public void setUp() {
073:                bout = new ByteArrayOutputStream();
074:                poifs = new POIFSFileSystem();
075:                dir = poifs.getRoot();
076:                dsi = null;
077:                try {
078:                    DocumentEntry dsiEntry = (DocumentEntry) dir
079:                            .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
080:                    DocumentInputStream dis = new DocumentInputStream(dsiEntry);
081:                    PropertySet ps = new PropertySet(dis);
082:                    dis.close();
083:                    dsi = new DocumentSummaryInformation(ps);
084:
085:                } catch (FileNotFoundException ex) {
086:                    /* There is no document summary information yet. We have to create a
087:                     * new one. */
088:                    dsi = PropertySetFactory.newDocumentSummaryInformation();
089:                    assertNotNull(dsi);
090:                } catch (IOException e) {
091:                    e.printStackTrace();
092:                    fail();
093:                } catch (NoPropertySetStreamException e) {
094:                    e.printStackTrace();
095:                    fail();
096:                } catch (MarkUnsupportedException e) {
097:                    e.printStackTrace();
098:                    fail();
099:                } catch (UnexpectedPropertySetTypeException e) {
100:                    e.printStackTrace();
101:                    fail();
102:                }
103:                assertNotNull(dsi);
104:                try {
105:                    DocumentEntry dsiEntry = (DocumentEntry) dir
106:                            .getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
107:                    DocumentInputStream dis = new DocumentInputStream(dsiEntry);
108:                    PropertySet ps = new PropertySet(dis);
109:                    dis.close();
110:                    si = new SummaryInformation(ps);
111:
112:                } catch (FileNotFoundException ex) {
113:                    /* There is no document summary information yet. We have to create a
114:                     * new one. */
115:                    si = PropertySetFactory.newSummaryInformation();
116:                    assertNotNull(si);
117:                } catch (IOException e) {
118:                    e.printStackTrace();
119:                    fail();
120:                } catch (NoPropertySetStreamException e) {
121:                    e.printStackTrace();
122:                    fail();
123:                } catch (MarkUnsupportedException e) {
124:                    e.printStackTrace();
125:                    fail();
126:                } catch (UnexpectedPropertySetTypeException e) {
127:                    e.printStackTrace();
128:                    fail();
129:                }
130:                assertNotNull(dsi);
131:
132:            }
133:
134:            /**
135:             * Setting a lot of things to null.
136:             */
137:            public void tearDown() {
138:                bout = null;
139:                poifs = null;
140:                dir = null;
141:                dsi = null;
142:
143:            }
144:
145:            /**
146:             * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream.
147:             * When finished writing information this method is used in the tests to
148:             * start reading from the created document and then the see if the results match.
149:             *
150:             */
151:            public void closeAndReOpen() {
152:
153:                try {
154:                    dsi.write(dir,
155:                            DocumentSummaryInformation.DEFAULT_STREAM_NAME);
156:                    si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
157:                } catch (WritingNotSupportedException e) {
158:                    e.printStackTrace();
159:                    fail();
160:                } catch (IOException e) {
161:                    e.printStackTrace();
162:                    fail();
163:                }
164:
165:                si = null;
166:                dsi = null;
167:                try {
168:
169:                    poifs.writeFilesystem(bout);
170:                    bout.flush();
171:
172:                } catch (IOException e) {
173:
174:                    e.printStackTrace();
175:                    fail();
176:                }
177:
178:                InputStream is = new ByteArrayInputStream(bout.toByteArray());
179:                assertNotNull(is);
180:                POIFSFileSystem poifs = null;
181:                try {
182:                    poifs = new POIFSFileSystem(is);
183:                } catch (IOException e) {
184:
185:                    e.printStackTrace();
186:                    fail();
187:                }
188:                try {
189:                    is.close();
190:                } catch (IOException e) {
191:                    e.printStackTrace();
192:                    fail();
193:                }
194:                assertNotNull(poifs);
195:                /* Read the document summary information. */
196:                DirectoryEntry dir = poifs.getRoot();
197:
198:                try {
199:                    DocumentEntry dsiEntry = (DocumentEntry) dir
200:                            .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
201:                    DocumentInputStream dis = new DocumentInputStream(dsiEntry);
202:                    PropertySet ps = new PropertySet(dis);
203:                    dis.close();
204:                    dsi = new DocumentSummaryInformation(ps);
205:                } catch (FileNotFoundException ex) {
206:                    fail();
207:                } catch (IOException e) {
208:                    e.printStackTrace();
209:                    fail();
210:                } catch (NoPropertySetStreamException e) {
211:                    e.printStackTrace();
212:                    fail();
213:                } catch (MarkUnsupportedException e) {
214:                    e.printStackTrace();
215:                    fail();
216:                } catch (UnexpectedPropertySetTypeException e) {
217:                    e.printStackTrace();
218:                    fail();
219:                }
220:                try {
221:                    DocumentEntry dsiEntry = (DocumentEntry) dir
222:                            .getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
223:                    DocumentInputStream dis = new DocumentInputStream(dsiEntry);
224:                    PropertySet ps = new PropertySet(dis);
225:                    dis.close();
226:                    si = new SummaryInformation(ps);
227:
228:                } catch (FileNotFoundException ex) {
229:                    /* There is no document summary information yet. We have to create a
230:                     * new one. */
231:                    si = PropertySetFactory.newSummaryInformation();
232:                    assertNotNull(si);
233:                } catch (IOException e) {
234:                    e.printStackTrace();
235:                    fail();
236:                } catch (NoPropertySetStreamException e) {
237:                    e.printStackTrace();
238:                    fail();
239:                } catch (MarkUnsupportedException e) {
240:                    e.printStackTrace();
241:                    fail();
242:                } catch (UnexpectedPropertySetTypeException e) {
243:                    e.printStackTrace();
244:                    fail();
245:                }
246:            }
247:
248:            /**
249:             * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it
250:             *
251:             */
252:            public void testOne() {
253:
254:                //DocumentSummaryInformation
255:                dsi.setCompany("xxxCompanyxxx");
256:                dsi.setManager("xxxManagerxxx");
257:                dsi.setCategory("xxxCategoryxxx");
258:
259:                //SummaryInformation
260:                si.setTitle("xxxTitlexxx");
261:                si.setAuthor("xxxAuthorxxx");
262:                si.setComments("xxxCommentsxxx");
263:                si.setKeywords("xxxKeyWordsxxx");
264:                si.setSubject("xxxSubjectxxx");
265:
266:                //Custom Properties (in DocumentSummaryInformation
267:                CustomProperties customProperties = dsi.getCustomProperties();
268:                if (customProperties == null) {
269:                    customProperties = new CustomProperties();
270:                }
271:
272:                /* Insert some custom properties into the container. */
273:                customProperties.put("Key1", "Value1");
274:                customProperties.put("Schlüssel2", "Wert2");
275:                customProperties.put("Sample Integer", new Integer(12345));
276:                customProperties.put("Sample Boolean", new Boolean(true));
277:                Date date = new Date();
278:                customProperties.put("Sample Date", date);
279:                customProperties.put("Sample Double", new Double(-1.0001));
280:                customProperties.put("Sample Negative Integer", new Integer(
281:                        -100000));
282:
283:                dsi.setCustomProperties(customProperties);
284:
285:                //start reading
286:                closeAndReOpen();
287:
288:                //testing
289:                assertNotNull(dsi);
290:                assertNotNull(si);
291:
292:                assertEquals("Category", "xxxCategoryxxx", dsi.getCategory());
293:                assertEquals("Company", "xxxCompanyxxx", dsi.getCompany());
294:                assertEquals("Manager", "xxxManagerxxx", dsi.getManager());
295:
296:                assertEquals("", "xxxAuthorxxx", si.getAuthor());
297:                assertEquals("", "xxxTitlexxx", si.getTitle());
298:                assertEquals("", "xxxCommentsxxx", si.getComments());
299:                assertEquals("", "xxxKeyWordsxxx", si.getKeywords());
300:                assertEquals("", "xxxSubjectxxx", si.getSubject());
301:
302:                /* Read the custom properties. If there are no custom properties yet,
303:                 * the application has to create a new CustomProperties object. It will
304:                 * serve as a container for custom properties. */
305:                customProperties = dsi.getCustomProperties();
306:                if (customProperties == null) {
307:                    fail();
308:                }
309:
310:                /* Insert some custom properties into the container. */
311:                String a1 = (String) customProperties.get("Key1");
312:                assertEquals("Key1", "Value1", a1);
313:                String a2 = (String) customProperties.get("Schlüssel2");
314:                assertEquals("Schlüssel2", "Wert2", a2);
315:                Integer a3 = (Integer) customProperties.get("Sample Integer");
316:                assertEquals("Sample Number", new Integer(12345), a3);
317:                Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
318:                assertEquals("Sample Boolean", new Boolean(true), a4);
319:                Date a5 = (Date) customProperties.get("Sample Date");
320:                assertEquals("Custom Date:", date, a5);
321:
322:                Double a6 = (Double) customProperties.get("Sample Double");
323:                assertEquals("Custom Float", new Double(-1.0001), a6);
324:
325:                Integer a7 = (Integer) customProperties
326:                        .get("Sample Negative Integer");
327:                assertEquals("Neg", new Integer(-100000), a7);
328:            }
329:
330:            /**
331:             * multiplies a string
332:             * @param s Input String
333:             * @return  the multiplied String
334:             */
335:            public String elongate(String s) {
336:                StringBuffer sb = new StringBuffer();
337:                for (int i = 0; i < 10000; i++) {
338:                    sb.append(s);
339:                    sb.append(" ");
340:                }
341:                return sb.toString();
342:            }
343:
344:            /**
345:             * Test very long input in each of the fields (approx 30-60KB each)
346:             *
347:             */
348:            public void testTwo() {
349:
350:                String company = elongate("company");
351:                String manager = elongate("manager");
352:                String category = elongate("category");
353:                String title = elongate("title");
354:                String author = elongate("author");
355:                String comments = elongate("comments");
356:                String keywords = elongate("keywords");
357:                String subject = elongate("subject");
358:                String p1 = elongate("p1");
359:                String p2 = elongate("p2");
360:                String k1 = elongate("k1");
361:                String k2 = elongate("k2");
362:
363:                dsi.setCompany(company);
364:                dsi.setManager(manager);
365:                dsi.setCategory(category);
366:
367:                si.setTitle(title);
368:                si.setAuthor(author);
369:                si.setComments(comments);
370:                si.setKeywords(keywords);
371:                si.setSubject(subject);
372:                CustomProperties customProperties = dsi.getCustomProperties();
373:                if (customProperties == null) {
374:                    customProperties = new CustomProperties();
375:                }
376:
377:                /* Insert some custom properties into the container. */
378:                customProperties.put(k1, p1);
379:                customProperties.put(k2, p2);
380:                customProperties.put("Sample Number", new Integer(12345));
381:                customProperties.put("Sample Boolean", new Boolean(true));
382:                Date date = new Date();
383:                customProperties.put("Sample Date", date);
384:
385:                dsi.setCustomProperties(customProperties);
386:
387:                closeAndReOpen();
388:
389:                assertNotNull(dsi);
390:                assertNotNull(si);
391:                /* Change the category to "POI example". Any former category value will
392:                 * be lost. If there has been no category yet, it will be created. */
393:                assertEquals("Category", category, dsi.getCategory());
394:                assertEquals("Company", company, dsi.getCompany());
395:                assertEquals("Manager", manager, dsi.getManager());
396:
397:                assertEquals("", author, si.getAuthor());
398:                assertEquals("", title, si.getTitle());
399:                assertEquals("", comments, si.getComments());
400:                assertEquals("", keywords, si.getKeywords());
401:                assertEquals("", subject, si.getSubject());
402:
403:                /* Read the custom properties. If there are no custom properties
404:                 * yet, the application has to create a new CustomProperties object.
405:                 * It will serve as a container for custom properties. */
406:                customProperties = dsi.getCustomProperties();
407:                if (customProperties == null) {
408:                    fail();
409:                }
410:
411:                /* Insert some custom properties into the container. */
412:                String a1 = (String) customProperties.get(k1);
413:                assertEquals("Key1", p1, a1);
414:                String a2 = (String) customProperties.get(k2);
415:                assertEquals("Schlüssel2", p2, a2);
416:                Integer a3 = (Integer) customProperties.get("Sample Number");
417:                assertEquals("Sample Number", new Integer(12345), a3);
418:                Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
419:                assertEquals("Sample Boolean", new Boolean(true), a4);
420:                Date a5 = (Date) customProperties.get("Sample Date");
421:                assertEquals("Custom Date:", date, a5);
422:
423:            }
424:
425:            /**
426:             * adds strange characters to the string
427:             * @param s Input String
428:             * @return  the multiplied String
429:             */
430:            public String strangize(String s) {
431:                StringBuffer sb = new StringBuffer();
432:                String[] umlaute = { "ä", "ü", "ö", "Ü", "$", "Ö", "Ü", "É",
433:                        "Ö", "@", "ç", "&" };
434:                char j = 0;
435:                Random rand = new Random();
436:                for (int i = 0; i < 5; i++) {
437:                    sb.append(s);
438:                    sb.append(" ");
439:                    j = (char) rand.nextInt(220);
440:                    j += 33;
441:                    // System.out.println(j);
442:                    sb.append(">");
443:                    sb.append(new Character(j));
444:                    sb.append("=");
445:                    sb.append(umlaute[rand.nextInt(umlaute.length)]);
446:                    sb.append("<");
447:                }
448:
449:                return sb.toString();
450:            }
451:
452:            /**
453:             * Tests with strange characters in keys and data (Umlaute etc.)
454:             *
455:             */
456:            public void testThree() {
457:
458:                String company = strangize("company");
459:                String manager = strangize("manager");
460:                String category = strangize("category");
461:                String title = strangize("title");
462:                String author = strangize("author");
463:                String comments = strangize("comments");
464:                String keywords = strangize("keywords");
465:                String subject = strangize("subject");
466:                String p1 = strangize("p1");
467:                String p2 = strangize("p2");
468:                String k1 = strangize("k1");
469:                String k2 = strangize("k2");
470:
471:                dsi.setCompany(company);
472:                dsi.setManager(manager);
473:                dsi.setCategory(category);
474:
475:                si.setTitle(title);
476:                si.setAuthor(author);
477:                si.setComments(comments);
478:                si.setKeywords(keywords);
479:                si.setSubject(subject);
480:                CustomProperties customProperties = dsi.getCustomProperties();
481:                if (customProperties == null) {
482:                    customProperties = new CustomProperties();
483:                }
484:
485:                /* Insert some custom properties into the container. */
486:                customProperties.put(k1, p1);
487:                customProperties.put(k2, p2);
488:                customProperties.put("Sample Number", new Integer(12345));
489:                customProperties.put("Sample Boolean", new Boolean(false));
490:                Date date = new Date(0);
491:                customProperties.put("Sample Date", date);
492:
493:                dsi.setCustomProperties(customProperties);
494:
495:                closeAndReOpen();
496:
497:                assertNotNull(dsi);
498:                assertNotNull(si);
499:                /* Change the category to "POI example". Any former category value will
500:                 * be lost. If there has been no category yet, it will be created. */
501:                assertEquals("Category", category, dsi.getCategory());
502:                assertEquals("Company", company, dsi.getCompany());
503:                assertEquals("Manager", manager, dsi.getManager());
504:
505:                assertEquals("", author, si.getAuthor());
506:                assertEquals("", title, si.getTitle());
507:                assertEquals("", comments, si.getComments());
508:                assertEquals("", keywords, si.getKeywords());
509:                assertEquals("", subject, si.getSubject());
510:
511:                /* Read the custom properties. If there are no custom properties yet,
512:                 * the application has to create a new CustomProperties object. It will
513:                 * serve as a container for custom properties. */
514:                customProperties = dsi.getCustomProperties();
515:                if (customProperties == null) {
516:                    fail();
517:                }
518:
519:                /* Insert some custom properties into the container. */
520:                // System.out.println(k1);
521:                String a1 = (String) customProperties.get(k1);
522:                assertEquals("Key1", p1, a1);
523:                String a2 = (String) customProperties.get(k2);
524:                assertEquals("Schlüssel2", p2, a2);
525:                Integer a3 = (Integer) customProperties.get("Sample Number");
526:                assertEquals("Sample Number", new Integer(12345), a3);
527:                Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
528:                assertEquals("Sample Boolean", new Boolean(false), a4);
529:                Date a5 = (Date) customProperties.get("Sample Date");
530:                assertEquals("Custom Date:", date, a5);
531:
532:            }
533:
534:            /**
535:             * Iterative testing: writing, reading etc.
536:             *
537:             */
538:            public void testFour() {
539:                for (int i = 1; i < 100; i++) {
540:                    setUp();
541:                    testThree();
542:                    tearDown();
543:                }
544:            }
545:
546:            /**
547:             * adds strange characters to the string with the adding of unicode characters
548:             * @param s Input String
549:             * @return  the multiplied String
550:             */
551:            public String strangizeU(String s) {
552:
553:                StringBuffer sb = new StringBuffer();
554:                String[] umlaute = { "ä", "ü", "ö", "Ü", "$", "Ö", "Ü", "É",
555:                        "Ö", "@", "ç", "&" };
556:                char j = 0;
557:                Random rand = new Random();
558:                for (int i = 0; i < 5; i++) {
559:                    sb.append(s);
560:                    sb.append(" ");
561:                    j = (char) rand.nextInt(220);
562:                    j += 33;
563:                    // System.out.println(j);
564:                    sb.append(">");
565:                    sb.append(new Character(j));
566:                    sb.append("=");
567:                    sb.append(umlaute[rand.nextInt(umlaute.length)]);
568:                    sb.append("<");
569:                }
570:                sb.append("äöü\uD840\uDC00");
571:                return sb.toString();
572:            }
573:
574:            /**
575:             * Unicode test
576:             *
577:             */
578:            public void testUnicode() {
579:                String company = strangizeU("company");
580:                String manager = strangizeU("manager");
581:                String category = strangizeU("category");
582:                String title = strangizeU("title");
583:                String author = strangizeU("author");
584:                String comments = strangizeU("comments");
585:                String keywords = strangizeU("keywords");
586:                String subject = strangizeU("subject");
587:                String p1 = strangizeU("p1");
588:                String p2 = strangizeU("p2");
589:                String k1 = strangizeU("k1");
590:                String k2 = strangizeU("k2");
591:
592:                dsi.setCompany(company);
593:                dsi.setManager(manager);
594:                dsi.setCategory(category);
595:
596:                si.setTitle(title);
597:                si.setAuthor(author);
598:                si.setComments(comments);
599:                si.setKeywords(keywords);
600:                si.setSubject(subject);
601:                CustomProperties customProperties = dsi.getCustomProperties();
602:                if (customProperties == null) {
603:                    customProperties = new CustomProperties();
604:                }
605:
606:                /* Insert some custom properties into the container. */
607:                customProperties.put(k1, p1);
608:                customProperties.put(k2, p2);
609:                customProperties.put("Sample Number", new Integer(12345));
610:                customProperties.put("Sample Boolean", new Boolean(true));
611:                Date date = new Date();
612:                customProperties.put("Sample Date", date);
613:
614:                dsi.setCustomProperties(customProperties);
615:
616:                closeAndReOpen();
617:
618:                assertNotNull(dsi);
619:                assertNotNull(si);
620:                /* Change the category to "POI example". Any former category value will
621:                 * be lost. If there has been no category yet, it will be created. */
622:                assertEquals("Category", category, dsi.getCategory());
623:                assertEquals("Company", company, dsi.getCompany());
624:                assertEquals("Manager", manager, dsi.getManager());
625:
626:                assertEquals("", author, si.getAuthor());
627:                assertEquals("", title, si.getTitle());
628:                assertEquals("", comments, si.getComments());
629:                assertEquals("", keywords, si.getKeywords());
630:                assertEquals("", subject, si.getSubject());
631:
632:                /* Read the custom properties. If there are no custom properties yet,
633:                 * the application has to create a new CustomProperties object. It will
634:                 * serve as a container for custom properties. */
635:                customProperties = dsi.getCustomProperties();
636:                if (customProperties == null) {
637:                    fail();
638:                }
639:
640:                /* Insert some custom properties into the container. */
641:                // System.out.println(k1);
642:                String a1 = (String) customProperties.get(k1);
643:                assertEquals("Key1", p1, a1);
644:                String a2 = (String) customProperties.get(k2);
645:                assertEquals("Schlüssel2", p2, a2);
646:                Integer a3 = (Integer) customProperties.get("Sample Number");
647:                assertEquals("Sample Number", new Integer(12345), a3);
648:                Boolean a4 = (Boolean) customProperties.get("Sample Boolean");
649:                assertEquals("Sample Boolean", new Boolean(true), a4);
650:                Date a5 = (Date) customProperties.get("Sample Date");
651:                assertEquals("Custom Date:", date, a5);
652:
653:            }
654:
655:            /**
656:             * Iterative testing of the unicode test
657:             *
658:             */
659:            public void testSix() {
660:                for (int i = 1; i < 100; i++) {
661:                    setUp();
662:                    testUnicode();
663:                    tearDown();
664:                }
665:            }
666:
667:            /**
668:             * Tests conversion in custom fields and errors
669:             *
670:             */
671:            public void testConvAndExistance() {
672:
673:                CustomProperties customProperties = dsi.getCustomProperties();
674:                if (customProperties == null) {
675:                    customProperties = new CustomProperties();
676:                }
677:
678:                /* Insert some custom properties into the container. */
679:                customProperties.put("int", new Integer(12345));
680:                customProperties.put("negint", new Integer(-12345));
681:                customProperties.put("long", new Long(12345));
682:                customProperties.put("neglong", new Long(-12345));
683:                customProperties.put("boolean", new Boolean(true));
684:                customProperties.put("string", "a String");
685:                //customProperties.put("float", new Float(12345.0));  is not valid
686:                //customProperties.put("negfloat", new Float(-12345.1)); is not valid
687:                customProperties.put("double", new Double(12345.2));
688:                customProperties.put("negdouble", new Double(-12345.3));
689:                //customProperties.put("char", new Character('a')); is not valid
690:
691:                Date date = new Date();
692:                customProperties.put("date", date);
693:
694:                dsi.setCustomProperties(customProperties);
695:
696:                closeAndReOpen();
697:
698:                assertNotNull(dsi);
699:                assertNotNull(si);
700:                /* Change the category to "POI example". Any former category value will
701:                 * be lost. If there has been no category yet, it will be created. */
702:                assertNull(dsi.getCategory());
703:                assertNull(dsi.getCompany());
704:                assertNull(dsi.getManager());
705:
706:                assertNull(si.getAuthor());
707:                assertNull(si.getTitle());
708:                assertNull(si.getComments());
709:                assertNull(si.getKeywords());
710:                assertNull(si.getSubject());
711:
712:                /* Read the custom properties. If there are no custom properties
713:                 * yet, the application has to create a new CustomProperties object.
714:                 * It will serve as a container for custom properties. */
715:                customProperties = dsi.getCustomProperties();
716:                if (customProperties == null) {
717:                    fail();
718:                }
719:
720:                /* Insert some custom properties into the container. */
721:
722:                Integer a3 = (Integer) customProperties.get("int");
723:                assertEquals("int", new Integer(12345), a3);
724:
725:                a3 = (Integer) customProperties.get("negint");
726:                assertEquals("negint", new Integer(-12345), a3);
727:
728:                Long al = (Long) customProperties.get("neglong");
729:                assertEquals("neglong", new Long(-12345), al);
730:
731:                al = (Long) customProperties.get("long");
732:                assertEquals("long", new Long(12345), al);
733:
734:                Boolean a4 = (Boolean) customProperties.get("boolean");
735:                assertEquals("boolean", new Boolean(true), a4);
736:
737:                Date a5 = (Date) customProperties.get("date");
738:                assertEquals("Custom Date:", date, a5);
739:
740:                Double d = (Double) customProperties.get("double");
741:                assertEquals("int", new Double(12345.2), d);
742:
743:                d = (Double) customProperties.get("negdouble");
744:                assertEquals("string", new Double(-12345.3), d);
745:
746:                String s = (String) customProperties.get("string");
747:                assertEquals("sring", "a String", s);
748:
749:                Object o = null;
750:
751:                o = customProperties.get("string");
752:                if (!(o instanceof  String)) {
753:                    fail();
754:                }
755:                o = customProperties.get("boolean");
756:                if (!(o instanceof  Boolean)) {
757:                    fail();
758:                }
759:
760:                o = customProperties.get("int");
761:                if (!(o instanceof  Integer)) {
762:                    fail();
763:                }
764:                o = customProperties.get("negint");
765:                if (!(o instanceof  Integer)) {
766:                    fail();
767:                }
768:
769:                o = customProperties.get("long");
770:                if (!(o instanceof  Long)) {
771:                    fail();
772:                }
773:                o = customProperties.get("neglong");
774:                if (!(o instanceof  Long)) {
775:                    fail();
776:                }
777:
778:                o = customProperties.get("double");
779:                if (!(o instanceof  Double)) {
780:                    fail();
781:                }
782:                o = customProperties.get("negdouble");
783:                if (!(o instanceof  Double)) {
784:                    fail();
785:                }
786:
787:                o = customProperties.get("date");
788:                if (!(o instanceof  Date)) {
789:                    fail();
790:                }
791:            }
792:
793:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.