unfinished release guide. It would be nice to have a html version.
[poi.git] / src / scratchpad / ooxml-testcases / org / apache / poi / hwpf / TestHWPFXML.java
blob0d8e196f4385102475157585d95746aeeb3c88a2
1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
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 package org.apache.poi.hwpf;
19 import java.io.File;
21 import org.apache.poi.hxf.HXFDocument;
22 import org.openxml4j.opc.Package;
23 import org.openxml4j.opc.PackagePart;
25 import junit.framework.TestCase;
27 public class TestHWPFXML extends TestCase {
28 private File sampleFile;
29 private File complexFile;
31 protected void setUp() throws Exception {
32 super.setUp();
34 sampleFile = new File(
35 System.getProperty("HWPF.testdata.path") +
36 File.separator + "sample.docx"
38 complexFile = new File(
39 System.getProperty("HWPF.testdata.path") +
40 File.separator + "IllustrativeCases.docx"
44 public void testContainsMainContentType() throws Exception {
45 Package pack = HXFDocument.openPackage(sampleFile);
47 boolean found = false;
48 for(PackagePart part : pack.getParts()) {
49 if(part.getContentType().equals(HWPFXML.MAIN_CONTENT_TYPE)) {
50 found = true;
52 System.out.println(part);
54 assertTrue(found);
57 public void testOpen() throws Exception {
58 HXFDocument.openPackage(sampleFile);
59 HXFDocument.openPackage(complexFile);
61 HWPFXML xml;
63 // Simple file
64 xml = new HWPFXML(
65 HXFDocument.openPackage(sampleFile)
67 // Check it has key parts
68 assertNotNull(xml.getDocument());
69 assertNotNull(xml.getDocumentBody());
70 assertNotNull(xml.getStyle());
72 // Complex file
73 xml = new HWPFXML(
74 HXFDocument.openPackage(complexFile)
76 assertNotNull(xml.getDocument());
77 assertNotNull(xml.getDocumentBody());
78 assertNotNull(xml.getStyle());
81 public void testMetadataBasics() throws Exception {
82 HWPFXML xml = new HWPFXML(
83 HXFDocument.openPackage(sampleFile)
85 assertNotNull(xml.getCoreProperties());
86 assertNotNull(xml.getExtendedProperties());
88 assertEquals("Microsoft Office Word", xml.getExtendedProperties().getApplication());
89 assertEquals(1315, xml.getExtendedProperties().getCharacters());
90 assertEquals(10, xml.getExtendedProperties().getLines());
92 assertEquals(null, xml.getCoreProperties().getTitleProperty().getValue());
93 assertEquals(null, xml.getCoreProperties().getSubjectProperty().getValue());
96 public void testMetadataComplex() throws Exception {
97 HWPFXML xml = new HWPFXML(
98 HXFDocument.openPackage(complexFile)
100 assertNotNull(xml.getCoreProperties());
101 assertNotNull(xml.getExtendedProperties());
103 assertEquals("Microsoft Office Outlook", xml.getExtendedProperties().getApplication());
104 assertEquals(5184, xml.getExtendedProperties().getCharacters());
105 assertEquals(0, xml.getExtendedProperties().getLines());
107 assertEquals(" ", xml.getCoreProperties().getTitleProperty().getValue());
108 assertEquals(" ", xml.getCoreProperties().getSubjectProperty().getValue());