You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/03/18 19:54:02 UTC
svn commit: r755699 [7/7] - in /poi/trunk/src:
examples/src/org/apache/poi/xssf/eventusermodel/examples/
ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/dev/
ooxml/java/org/apache/poi/extractor/
ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/...
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java Wed Mar 18 18:54:01 2009
@@ -1,208 +1,208 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.openxml4j.opc.compliance;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
-import org.apache.poi.openxml4j.opc.ContentTypes;
-import org.apache.poi.openxml4j.opc.Package;
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.openxml4j.opc.TargetMode;
-
-/**
- * Test core properties Open Packaging Convention compliance.
- *
- * M4.1: The format designer shall specify and the format producer shall create
- * at most one core properties relationship for a package. A format consumer
- * shall consider more than one core properties relationship for a package to be
- * an error. If present, the relationship shall target the Core Properties part.
- *
- * M4.2: The format designer shall not specify and the format producer shall not
- * create Core Properties that use the Markup Compatibility namespace as defined
- * in Annex F, "Standard Namespaces and Content Types". A format consumer shall
- * consider the use of the Markup Compatibility namespace to be an error.
- *
- * M4.3: Producers shall not create a document element that contains refinements
- * to the Dublin Core elements, except for the two specified in the schema:
- * <dcterms:created> and <dcterms:modified> Consumers shall consider a document
- * element that violates this constraint to be an error.
- *
- * M4.4: Producers shall not create a document element that contains the
- * xml:lang attribute. Consumers shall consider a document element that violates
- * this constraint to be an error.
- *
- * M4.5: Producers shall not create a document element that contains the
- * xsi:type attribute, except for a <dcterms:created> or <dcterms:modified>
- * element where the xsi:type attribute shall be present and shall hold the
- * value dcterms:W3CDTF, where dcterms is the namespace prefix of the Dublin
- * Core namespace. Consumers shall consider a document element that violates
- * this constraint to be an error.
- *
- * @author Julien Chable
- */
-public final class TestOPCComplianceCoreProperties extends TestCase {
-
- public void testCorePropertiesPart() {
- Package pkg;
- try {
- InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
- pkg = Package.open(is);
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- pkg.revert();
- }
-
- private static String extractInvalidFormatMessage(String sampleNameSuffix) {
-
- InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
- Package pkg;
- try {
- pkg = Package.open(is);
- } catch (InvalidFormatException e) {
- // expected during successful test
- return e.getMessage();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- pkg.revert();
- // Normally must thrown an InvalidFormatException exception.
- throw new AssertionFailedError("expected OPC compliance exception was not thrown");
- }
-
- /**
- * Test M4.1 rule.
- */
- public void testOnlyOneCorePropertiesPart() {
- String msg = extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");
- assertEquals("OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !", msg);
- }
-
- private static URI createURI(String text) {
- try {
- return new URI(text);
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Test M4.1 rule.
- */
- public void testOnlyOneCorePropertiesPart_AddRelationship() {
- InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
- Package pkg;
- try {
- pkg = Package.open(is);
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- URI partUri = createURI("/docProps/core2.xml");
- try {
- pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
- PackageRelationshipTypes.CORE_PROPERTIES);
- fail("expected OPC compliance exception was not thrown");
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (InvalidOperationException e) {
- // expected during successful test
- assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
- }
- pkg.revert();
- }
-
- /**
- * Test M4.1 rule.
- */
- public void testOnlyOneCorePropertiesPart_AddPart() {
- String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
- Package pkg = null;
- try {
- pkg = Package.open(sampleFileName);
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- }
-
- URI partUri = createURI("/docProps/core2.xml");
- try {
- pkg.createPart(PackagingURIHelper.createPartName(partUri),
- ContentTypes.CORE_PROPERTIES_PART);
- fail("expected OPC compliance exception was not thrown");
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (InvalidOperationException e) {
- // expected during successful test
- assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
- }
- pkg.revert();
- }
-
- /**
- * Test M4.2 rule.
- */
- public void testDoNotUseCompatibilityMarkup() {
- String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");
- assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);
- }
-
- /**
- * Test M4.3 rule.
- */
- public void testDCTermsNamespaceLimitedUse() {
- String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");
- assertEquals("OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.", msg);
- }
-
- /**
- * Test M4.4 rule.
- */
- public void testUnauthorizedXMLLangAttribute() {
- String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");
- assertEquals("OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.", msg);
- }
-
- /**
- * Test M4.5 rule.
- */
- public void testLimitedXSITypeAttribute_NotPresent() {
- String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");
- assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);
- }
-
- /**
- * Test M4.5 rule.
- */
- public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {
- String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
- assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF' !", msg);
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.openxml4j.opc.compliance;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
+import org.apache.poi.openxml4j.opc.ContentTypes;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
+
+/**
+ * Test core properties Open Packaging Convention compliance.
+ *
+ * M4.1: The format designer shall specify and the format producer shall create
+ * at most one core properties relationship for a package. A format consumer
+ * shall consider more than one core properties relationship for a package to be
+ * an error. If present, the relationship shall target the Core Properties part.
+ *
+ * M4.2: The format designer shall not specify and the format producer shall not
+ * create Core Properties that use the Markup Compatibility namespace as defined
+ * in Annex F, "Standard Namespaces and Content Types". A format consumer shall
+ * consider the use of the Markup Compatibility namespace to be an error.
+ *
+ * M4.3: Producers shall not create a document element that contains refinements
+ * to the Dublin Core elements, except for the two specified in the schema:
+ * <dcterms:created> and <dcterms:modified> Consumers shall consider a document
+ * element that violates this constraint to be an error.
+ *
+ * M4.4: Producers shall not create a document element that contains the
+ * xml:lang attribute. Consumers shall consider a document element that violates
+ * this constraint to be an error.
+ *
+ * M4.5: Producers shall not create a document element that contains the
+ * xsi:type attribute, except for a <dcterms:created> or <dcterms:modified>
+ * element where the xsi:type attribute shall be present and shall hold the
+ * value dcterms:W3CDTF, where dcterms is the namespace prefix of the Dublin
+ * Core namespace. Consumers shall consider a document element that violates
+ * this constraint to be an error.
+ *
+ * @author Julien Chable
+ */
+public final class TestOPCComplianceCoreProperties extends TestCase {
+
+ public void testCorePropertiesPart() {
+ OPCPackage pkg;
+ try {
+ InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
+ pkg = OPCPackage.open(is);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ pkg.revert();
+ }
+
+ private static String extractInvalidFormatMessage(String sampleNameSuffix) {
+
+ InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
+ OPCPackage pkg;
+ try {
+ pkg = OPCPackage.open(is);
+ } catch (InvalidFormatException e) {
+ // expected during successful test
+ return e.getMessage();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ pkg.revert();
+ // Normally must thrown an InvalidFormatException exception.
+ throw new AssertionFailedError("expected OPC compliance exception was not thrown");
+ }
+
+ /**
+ * Test M4.1 rule.
+ */
+ public void testOnlyOneCorePropertiesPart() {
+ String msg = extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");
+ assertEquals("OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !", msg);
+ }
+
+ private static URI createURI(String text) {
+ try {
+ return new URI(text);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Test M4.1 rule.
+ */
+ public void testOnlyOneCorePropertiesPart_AddRelationship() {
+ InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
+ OPCPackage pkg;
+ try {
+ pkg = OPCPackage.open(is);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ URI partUri = createURI("/docProps/core2.xml");
+ try {
+ pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
+ PackageRelationshipTypes.CORE_PROPERTIES);
+ fail("expected OPC compliance exception was not thrown");
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (InvalidOperationException e) {
+ // expected during successful test
+ assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
+ }
+ pkg.revert();
+ }
+
+ /**
+ * Test M4.1 rule.
+ */
+ public void testOnlyOneCorePropertiesPart_AddPart() {
+ String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
+ OPCPackage pkg = null;
+ try {
+ pkg = OPCPackage.open(sampleFileName);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ }
+
+ URI partUri = createURI("/docProps/core2.xml");
+ try {
+ pkg.createPart(PackagingURIHelper.createPartName(partUri),
+ ContentTypes.CORE_PROPERTIES_PART);
+ fail("expected OPC compliance exception was not thrown");
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (InvalidOperationException e) {
+ // expected during successful test
+ assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
+ }
+ pkg.revert();
+ }
+
+ /**
+ * Test M4.2 rule.
+ */
+ public void testDoNotUseCompatibilityMarkup() {
+ String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");
+ assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);
+ }
+
+ /**
+ * Test M4.3 rule.
+ */
+ public void testDCTermsNamespaceLimitedUse() {
+ String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");
+ assertEquals("OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.", msg);
+ }
+
+ /**
+ * Test M4.4 rule.
+ */
+ public void testUnauthorizedXMLLangAttribute() {
+ String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");
+ assertEquals("OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.", msg);
+ }
+
+ /**
+ * Test M4.5 rule.
+ */
+ public void testLimitedXSITypeAttribute_NotPresent() {
+ String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");
+ assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);
+ }
+
+ /**
+ * Test M4.5 rule.
+ */
+ public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {
+ String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
+ assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF' !", msg);
+ }
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java Wed Mar 18 18:54:01 2009
@@ -1,162 +1,162 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.openxml4j.opc.compliance;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
-import org.apache.poi.openxml4j.opc.ContentTypes;
-import org.apache.poi.openxml4j.opc.Package;
-import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.openxml4j.opc.TargetMode;
-
-/**
- * Test Open Packaging Convention package model compliance.
- *
- * M1.11 : A package implementer shall neither create nor recognize a part with
- * a part name derived from another part name by appending segments to it.
- *
- * @author Julien Chable
- */
-public class TestOPCCompliancePackageModel extends TestCase {
-
- public TestOPCCompliancePackageModel(String name) {
- super(name);
- }
-
- /**
- * A package implementer shall neither create nor recognize a part with a
- * part name derived from another part name by appending segments to it.
- * [M1.11]
- */
- public void testPartNameDerivationAdditionFailure() {
- Package pkg = Package.create("TODELETEIFEXIST.docx");
- try {
- PackagePartName name = PackagingURIHelper
- .createPartName("/word/document.xml");
- PackagePartName nameDerived = PackagingURIHelper
- .createPartName("/word/document.xml/image1.gif");
- pkg.createPart(name, ContentTypes.XML);
- pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
- } catch (InvalidOperationException e) {
- pkg.revert();
- return;
- } catch (InvalidFormatException e) {
- fail(e.getMessage());
- }
- fail("A package implementer shall neither create nor recognize a part with a"
- + " part name derived from another part name by appending segments to it."
- + " [M1.11]");
- }
-
- /**
- * A package implementer shall neither create nor recognize a part with a
- * part name derived from another part name by appending segments to it.
- * [M1.11]
- */
- public void testPartNameDerivationReadingFailure() {
- String filepath = System.getProperty("openxml4j.compliance.input")
- + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
- try {
- Package.open(filepath);
- } catch (InvalidFormatException e) {
- return;
- }
- fail("A package implementer shall neither create nor recognize a part with a"
- + " part name derived from another part name by appending segments to it."
- + " [M1.11]");
- }
-
- /**
- * Rule M1.12 : Packages shall not contain equivalent part names and package
- * implementers shall neither create nor recognize packages with equivalent
- * part names.
- */
- public void testAddPackageAlreadyAddFailure() throws Exception {
- Package pkg = Package.create("DELETEIFEXISTS.docx");
- PackagePartName name1 = null;
- PackagePartName name2 = null;
- try {
- name1 = PackagingURIHelper.createPartName("/word/document.xml");
- name2 = PackagingURIHelper.createPartName("/word/document.xml");
- } catch (InvalidFormatException e) {
- throw new Exception(e.getMessage());
- }
- pkg.createPart(name1, ContentTypes.XML);
- try {
- pkg.createPart(name2, ContentTypes.XML);
- } catch (InvalidOperationException e) {
- return;
- }
- fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
- }
-
- /**
- * Rule M1.12 : Packages shall not contain equivalent part names and package
- * implementers shall neither create nor recognize packages with equivalent
- * part names.
- */
- public void testAddPackageAlreadyAddFailure2() throws Exception {
- Package pkg = Package.create("DELETEIFEXISTS.docx");
- PackagePartName partName = null;
- try {
- partName = PackagingURIHelper.createPartName("/word/document.xml");
- } catch (InvalidFormatException e) {
- throw new Exception(e.getMessage());
- }
- pkg.createPart(partName, ContentTypes.XML);
- try {
- pkg.createPart(partName, ContentTypes.XML);
- } catch (InvalidOperationException e) {
- return;
- }
- fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
- }
-
- /**
- * Try to add a relationship to a relationship part.
- *
- * Check rule M1.25: The Relationships part shall not have relationships to
- * any other part. Package implementers shall enforce this requirement upon
- * the attempt to create such a relationship and shall treat any such
- * relationship as invalid.
- */
- public void testAddRelationshipRelationshipsPartFailure() {
- Package pkg = Package.create("DELETEIFEXISTS.docx");
- PackagePartName name1 = null;
- try {
- name1 = PackagingURIHelper
- .createPartName("/test/_rels/document.xml.rels");
- } catch (InvalidFormatException e) {
- fail("This exception should never happen !");
- }
-
- try {
- pkg.addRelationship(name1, TargetMode.INTERNAL,
- PackageRelationshipTypes.CORE_DOCUMENT);
- } catch (InvalidOperationException e) {
- return;
- }
- fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.openxml4j.opc.compliance;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
+import org.apache.poi.openxml4j.opc.ContentTypes;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
+
+/**
+ * Test Open Packaging Convention package model compliance.
+ *
+ * M1.11 : A package implementer shall neither create nor recognize a part with
+ * a part name derived from another part name by appending segments to it.
+ *
+ * @author Julien Chable
+ */
+public class TestOPCCompliancePackageModel extends TestCase {
+
+ public TestOPCCompliancePackageModel(String name) {
+ super(name);
+ }
+
+ /**
+ * A package implementer shall neither create nor recognize a part with a
+ * part name derived from another part name by appending segments to it.
+ * [M1.11]
+ */
+ public void testPartNameDerivationAdditionFailure() {
+ OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
+ try {
+ PackagePartName name = PackagingURIHelper
+ .createPartName("/word/document.xml");
+ PackagePartName nameDerived = PackagingURIHelper
+ .createPartName("/word/document.xml/image1.gif");
+ pkg.createPart(name, ContentTypes.XML);
+ pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
+ } catch (InvalidOperationException e) {
+ pkg.revert();
+ return;
+ } catch (InvalidFormatException e) {
+ fail(e.getMessage());
+ }
+ fail("A package implementer shall neither create nor recognize a part with a"
+ + " part name derived from another part name by appending segments to it."
+ + " [M1.11]");
+ }
+
+ /**
+ * A package implementer shall neither create nor recognize a part with a
+ * part name derived from another part name by appending segments to it.
+ * [M1.11]
+ */
+ public void testPartNameDerivationReadingFailure() {
+ String filepath = System.getProperty("openxml4j.compliance.input")
+ + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";
+ try {
+ OPCPackage.open(filepath);
+ } catch (InvalidFormatException e) {
+ return;
+ }
+ fail("A package implementer shall neither create nor recognize a part with a"
+ + " part name derived from another part name by appending segments to it."
+ + " [M1.11]");
+ }
+
+ /**
+ * Rule M1.12 : Packages shall not contain equivalent part names and package
+ * implementers shall neither create nor recognize packages with equivalent
+ * part names.
+ */
+ public void testAddPackageAlreadyAddFailure() throws Exception {
+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+ PackagePartName name1 = null;
+ PackagePartName name2 = null;
+ try {
+ name1 = PackagingURIHelper.createPartName("/word/document.xml");
+ name2 = PackagingURIHelper.createPartName("/word/document.xml");
+ } catch (InvalidFormatException e) {
+ throw new Exception(e.getMessage());
+ }
+ pkg.createPart(name1, ContentTypes.XML);
+ try {
+ pkg.createPart(name2, ContentTypes.XML);
+ } catch (InvalidOperationException e) {
+ return;
+ }
+ fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
+ }
+
+ /**
+ * Rule M1.12 : Packages shall not contain equivalent part names and package
+ * implementers shall neither create nor recognize packages with equivalent
+ * part names.
+ */
+ public void testAddPackageAlreadyAddFailure2() throws Exception {
+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+ PackagePartName partName = null;
+ try {
+ partName = PackagingURIHelper.createPartName("/word/document.xml");
+ } catch (InvalidFormatException e) {
+ throw new Exception(e.getMessage());
+ }
+ pkg.createPart(partName, ContentTypes.XML);
+ try {
+ pkg.createPart(partName, ContentTypes.XML);
+ } catch (InvalidOperationException e) {
+ return;
+ }
+ fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
+ }
+
+ /**
+ * Try to add a relationship to a relationship part.
+ *
+ * Check rule M1.25: The Relationships part shall not have relationships to
+ * any other part. Package implementers shall enforce this requirement upon
+ * the attempt to create such a relationship and shall treat any such
+ * relationship as invalid.
+ */
+ public void testAddRelationshipRelationshipsPartFailure() {
+ OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+ PackagePartName name1 = null;
+ try {
+ name1 = PackagingURIHelper
+ .createPartName("/test/_rels/document.xml.rels");
+ } catch (InvalidFormatException e) {
+ fail("This exception should never happen !");
+ }
+
+ try {
+ pkg.addRelationship(name1, TargetMode.INTERNAL,
+ PackageRelationshipTypes.CORE_DOCUMENT);
+ } catch (InvalidOperationException e) {
+ return;
+ }
+ fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
+ }
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Wed Mar 18 18:54:01 2009
@@ -24,7 +24,7 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import junit.framework.TestCase;
@@ -63,7 +63,7 @@
// Package -> xssf
wb = WorkbookFactory.create(
- Package.open(xlsx.toString())
+ OPCPackage.open(xlsx.toString())
);
assertNotNull(wb);
assertTrue(wb instanceof XSSFWorkbook);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFSlideShow.java Wed Mar 18 18:54:01 2009
@@ -18,14 +18,14 @@
import java.io.File;
+import junit.framework.TestCase;
+
import org.apache.poi.POIXMLDocument;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
-import junit.framework.TestCase;
-
public class TestXSLFSlideShow extends TestCase {
private String sampleFile;
@@ -39,7 +39,7 @@
}
public void testContainsMainContentType() throws Exception {
- Package pack = POIXMLDocument.openPackage(sampleFile);
+ OPCPackage pack = POIXMLDocument.openPackage(sampleFile);
boolean found = false;
for(PackagePart part : pack.getParts()) {
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/XSSFTestDataSamples.java Wed Mar 18 18:54:01 2009
@@ -1,75 +1,80 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.xssf;
-
-import java.io.*;
-
-import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.Package;
-
-/**
- * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
- *
- * @author Josh Micich
- */
-public class XSSFTestDataSamples {
- public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
- InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
- try {
- Package pkg = Package.open(is);
- return new XSSFWorkbook(pkg);
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- public static <R extends Workbook> R writeOutAndReadBack(R wb) {
- Workbook result;
- try {
- if (wb instanceof HSSFWorkbook) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
- wb.write(baos);
- InputStream is = new ByteArrayInputStream(baos.toByteArray());
- result = new HSSFWorkbook(is);
- } else if (wb instanceof XSSFWorkbook) {
- File tmp = File.createTempFile("poi-ooxml-", ".xlsx");
- tmp.deleteOnExit();
- FileOutputStream out = new FileOutputStream(tmp);
- wb.write(out);
- out.close();
- Package pkg = Package.open(tmp.getAbsolutePath());
- result = new XSSFWorkbook(pkg);
- } else {
- throw new RuntimeException("Unexpected workbook type ("
- + wb.getClass().getName() + ")");
- }
- } catch (InvalidFormatException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- @SuppressWarnings("unchecked")
- R r = (R) result;
- return r;
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+/**
+ * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder.
+ *
+ * @author Josh Micich
+ */
+public class XSSFTestDataSamples {
+ public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
+ InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
+ try {
+ OPCPackage pkg = OPCPackage.open(is);
+ return new XSSFWorkbook(pkg);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ public static <R extends Workbook> R writeOutAndReadBack(R wb) {
+ Workbook result;
+ try {
+ if (wb instanceof HSSFWorkbook) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
+ wb.write(baos);
+ InputStream is = new ByteArrayInputStream(baos.toByteArray());
+ result = new HSSFWorkbook(is);
+ } else if (wb instanceof XSSFWorkbook) {
+ File tmp = File.createTempFile("poi-ooxml-", ".xlsx");
+ tmp.deleteOnExit();
+ FileOutputStream out = new FileOutputStream(tmp);
+ wb.write(out);
+ out.close();
+ OPCPackage pkg = OPCPackage.open(tmp.getAbsolutePath());
+ result = new XSSFWorkbook(pkg);
+ } else {
+ throw new RuntimeException("Unexpected workbook type ("
+ + wb.getClass().getName() + ")");
+ }
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ @SuppressWarnings("unchecked")
+ R r = (R) result;
+ return r;
+ }
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java Wed Mar 18 18:54:01 2009
@@ -25,7 +25,7 @@
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
/**
* Tests for XSSFReader
@@ -49,7 +49,7 @@
public void testGetBits() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
- Package pkg = Package.open(f.toString());
+ OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@@ -63,7 +63,7 @@
public void testStyles() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
- Package pkg = Package.open(f.toString());
+ OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@@ -73,7 +73,7 @@
public void testStrings() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
- Package pkg = Package.open(f.toString());
+ OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
@@ -83,7 +83,7 @@
public void testSheets() throws Exception {
File f = new File(dirName, "SampleSS.xlsx");
- Package pkg = Package.open(f.toString());
+ OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
byte[] data = new byte[4096];
@@ -116,7 +116,7 @@
*/
public void testOrderOfSheets() throws Exception {
File f = new File(dirName, "reordered_sheets.xlsx");
- Package pkg = Package.open(f.toString());
+ OPCPackage pkg = OPCPackage.open(f.toString());
XSSFReader r = new XSSFReader(pkg);
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java Wed Mar 18 18:54:01 2009
@@ -32,7 +32,7 @@
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import junit.framework.TestCase;
@@ -125,7 +125,7 @@
);
assertTrue(xml.exists());
- Package pkg = Package.open(xml.toString());
+ OPCPackage pkg = OPCPackage.open(xml.toString());
XSSFWorkbook wb = new XSSFWorkbook(pkg);
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
CommentsTable ct = null;
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java Wed Mar 18 18:54:01 2009
@@ -32,7 +32,7 @@
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
/**
* Performs much the same role as {@link TestFormulasFromSpreadsheet},
@@ -149,7 +149,7 @@
protected void setUp() throws Exception {
if (workbook == null) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(SS.FILENAME);
- Package pkg = Package.open(is);
+ OPCPackage pkg = OPCPackage.open(is);
workbook = new XSSFWorkbook( pkg );
sheet = workbook.getSheetAt( 0 );
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Wed Mar 18 18:54:01 2009
@@ -21,7 +21,8 @@
import junit.framework.TestCase;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -71,7 +72,7 @@
* We should carry vba macros over after save
*/
public void test45431() throws Exception {
- Package pkg = Package.open(getFilePath("45431.xlsm"));
+ OPCPackage pkg = OPCPackage.open(getFilePath("45431.xlsm"));
XSSFWorkbook wb = new XSSFWorkbook(pkg);
assertTrue(wb.isMacroEnabled());
@@ -89,7 +90,7 @@
// Save and re-open, both still there
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
- Package nPkg = nwb.getPackage();
+ OPCPackage nPkg = nwb.getPackage();
assertTrue(nwb.isMacroEnabled());
vba = nPkg.getPart(
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Wed Mar 18 18:54:01 2009
@@ -1,77 +1,79 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.xssf.usermodel;
-
-import junit.framework.TestCase;
-import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.apache.poi.POIXMLDocumentPart;
-
-import java.util.List;
-
-/**
- * @author Yegor Kozlov
- */
-public class TestXSSFDrawing extends TestCase {
- public void testRead(){
- XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
- XSSFSheet sheet = wb.getSheetAt(0);
- //the sheet has one relationship and it is XSSFDrawing
- List<POIXMLDocumentPart> rels = sheet.getRelations();
- assertEquals(1, rels.size());
- assertTrue(rels.get(0) instanceof XSSFDrawing);
-
- XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
- //sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing
- assertSame(drawing, sheet.createDrawingPatriarch());
- String drawingId = drawing.getPackageRelationship().getId();
-
- //there should be a relation to this drawing in the worksheet
- assertTrue(sheet.getCTWorksheet().isSetDrawing());
- assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
-
- }
-
- public void testNew(){
- XSSFWorkbook wb = new XSSFWorkbook();
- XSSFSheet sheet = wb.createSheet();
- //multiple calls of createDrawingPatriarch should return the same instance of XSSFDrawing
- XSSFDrawing dr1 = sheet.createDrawingPatriarch();
- XSSFDrawing dr2 = sheet.createDrawingPatriarch();
- assertSame(dr1, dr2);
-
- List<POIXMLDocumentPart> rels = sheet.getRelations();
- assertEquals(1, rels.size());
- assertTrue(rels.get(0) instanceof XSSFDrawing);
-
- XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
- String drawingId = drawing.getPackageRelationship().getId();
-
- //there should be a relation to this drawing in the worksheet
- assertTrue(sheet.getCTWorksheet().isSetDrawing());
- assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
-
- }
- public void testMultipleDrawings(){
- XSSFWorkbook wb = new XSSFWorkbook();
- for (int i = 0; i < 3; i++) {
- XSSFSheet sheet = wb.createSheet();
- XSSFDrawing drawing = sheet.createDrawingPatriarch();
- }
- org.apache.poi.openxml4j.opc.Package pkg = wb.getPackage();
- assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
- }
-}
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf.usermodel;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xssf.XSSFTestDataSamples;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class TestXSSFDrawing extends TestCase {
+ public void testRead(){
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
+ XSSFSheet sheet = wb.getSheetAt(0);
+ //the sheet has one relationship and it is XSSFDrawing
+ List<POIXMLDocumentPart> rels = sheet.getRelations();
+ assertEquals(1, rels.size());
+ assertTrue(rels.get(0) instanceof XSSFDrawing);
+
+ XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
+ //sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing
+ assertSame(drawing, sheet.createDrawingPatriarch());
+ String drawingId = drawing.getPackageRelationship().getId();
+
+ //there should be a relation to this drawing in the worksheet
+ assertTrue(sheet.getCTWorksheet().isSetDrawing());
+ assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
+
+ }
+
+ public void testNew(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ //multiple calls of createDrawingPatriarch should return the same instance of XSSFDrawing
+ XSSFDrawing dr1 = sheet.createDrawingPatriarch();
+ XSSFDrawing dr2 = sheet.createDrawingPatriarch();
+ assertSame(dr1, dr2);
+
+ List<POIXMLDocumentPart> rels = sheet.getRelations();
+ assertEquals(1, rels.size());
+ assertTrue(rels.get(0) instanceof XSSFDrawing);
+
+ XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
+ String drawingId = drawing.getPackageRelationship().getId();
+
+ //there should be a relation to this drawing in the worksheet
+ assertTrue(sheet.getCTWorksheet().isSetDrawing());
+ assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
+
+ }
+ public void testMultipleDrawings(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ for (int i = 0; i < 3; i++) {
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ }
+ OPCPackage pkg = wb.getPackage();
+ assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
+ }
+}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Wed Mar 18 18:54:01 2009
@@ -29,7 +29,7 @@
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.openxml4j.opc.ContentTypes;
-import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
@@ -251,7 +251,7 @@
out.close();
// Check the package contains what we'd expect it to
- Package pkg = Package.open(file.toString());
+ OPCPackage pkg = OPCPackage.open(file.toString());
PackagePart wbRelPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
assertNotNull(wbRelPart);
@@ -293,7 +293,7 @@
assertNotNull(workbook.getStylesSource());
// And check a few low level bits too
- Package pkg = Package.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
+ OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
PackagePart wbPart =
pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?rev=755699&r1=755698&r2=755699&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Wed Mar 18 18:54:01 2009
@@ -18,13 +18,13 @@
import java.io.File;
+import junit.framework.TestCase;
+
import org.apache.poi.POIXMLDocument;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
-import org.apache.poi.openxml4j.opc.Package;
-import org.apache.poi.openxml4j.opc.PackagePart;
-
-import junit.framework.TestCase;
public class TestXWPFDocument extends TestCase {
private File sampleFile;
@@ -47,7 +47,7 @@
}
public void testContainsMainContentType() throws Exception {
- Package pack = POIXMLDocument.openPackage(sampleFile.toString());
+ OPCPackage pack = POIXMLDocument.openPackage(sampleFile.toString());
boolean found = false;
for(PackagePart part : pack.getParts()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org