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;
019:
020: import junit.framework.TestCase;
021: import java.io.*;
022:
023: import org.apache.poi.hslf.HSLFSlideShow;
024: import org.apache.poi.hwpf.HWPFDocument;
025: import org.apache.poi.poifs.filesystem.*;
026:
027: /**
028: * Tests that POIDocument correctly loads and saves the common
029: * (hspf) Document Properties
030: *
031: * This is part 2 of 2 of the tests - it only does the POIDocuments
032: * which are part of the scratchpad (not main)
033: *
034: * @author Nick Burch (nick at torchbox dot com)
035: */
036: public class TestPOIDocumentScratchpad extends TestCase {
037: // The POI Documents to work on
038: private POIDocument doc;
039: private POIDocument doc2;
040: // POIFS primed on the test (powerpoint and word) data
041: private POIFSFileSystem pfs;
042: private POIFSFileSystem pfs2;
043:
044: /**
045: * Set things up, using a PowerPoint document and
046: * a Word Document for our testing
047: */
048: public void setUp() throws Exception {
049: String dirnameHSLF = System.getProperty("HSLF.testdata.path");
050: String filenameHSLF = dirnameHSLF + "/basic_test_ppt_file.ppt";
051: String dirnameHSSF = System.getProperty("HSSF.testdata.path");
052: String filenameHSSF = dirnameHSLF + "/DateFormats.ppt";
053: String dirnameHWPF = System.getProperty("HWPF.testdata.path");
054: String filenameHWPF = dirnameHWPF + "/test2.doc";
055:
056: FileInputStream fisHSLF = new FileInputStream(filenameHSLF);
057: pfs = new POIFSFileSystem(fisHSLF);
058: doc = new HSLFSlideShow(pfs);
059:
060: FileInputStream fisHWPF = new FileInputStream(filenameHWPF);
061: pfs2 = new POIFSFileSystem(fisHWPF);
062: doc2 = new HWPFDocument(pfs2);
063: }
064:
065: public void testReadProperties() throws Exception {
066: // We should have both sets
067: assertNotNull(doc.getDocumentSummaryInformation());
068: assertNotNull(doc.getSummaryInformation());
069:
070: // Check they are as expected for the test doc
071: assertEquals("Hogwarts", doc.getSummaryInformation()
072: .getAuthor());
073: assertEquals(10598, doc.getDocumentSummaryInformation()
074: .getByteCount());
075: }
076:
077: public void testReadProperties2() throws Exception {
078: // Check again on the word one
079: assertNotNull(doc2.getDocumentSummaryInformation());
080: assertNotNull(doc2.getSummaryInformation());
081:
082: assertEquals("Hogwarts", doc2.getSummaryInformation()
083: .getAuthor());
084: assertEquals("", doc2.getSummaryInformation().getKeywords());
085: assertEquals(0, doc2.getDocumentSummaryInformation()
086: .getByteCount());
087: }
088:
089: public void testWriteProperties() throws Exception {
090: // Just check we can write them back out into a filesystem
091: POIFSFileSystem outFS = new POIFSFileSystem();
092: doc.writeProperties(outFS);
093:
094: // Should now hold them
095: assertNotNull(outFS
096: .createDocumentInputStream("\005SummaryInformation"));
097: assertNotNull(outFS
098: .createDocumentInputStream("\005DocumentSummaryInformation"));
099: }
100:
101: public void testWriteReadProperties() throws Exception {
102: ByteArrayOutputStream baos = new ByteArrayOutputStream();
103:
104: // Write them out
105: POIFSFileSystem outFS = new POIFSFileSystem();
106: doc.writeProperties(outFS);
107: outFS.writeFilesystem(baos);
108:
109: // Create a new version
110: ByteArrayInputStream bais = new ByteArrayInputStream(baos
111: .toByteArray());
112: POIFSFileSystem inFS = new POIFSFileSystem(bais);
113:
114: // Check they're still there
115: doc.filesystem = inFS;
116: doc.readProperties();
117:
118: // Delegate test
119: testReadProperties();
120: }
121: }
|