From f8fcefcd137ffb8753a7108d2c46979f2069886f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 8 Jul 2016 12:07:20 +0000 Subject: [PATCH] convert OPC Compliance unit tests to junit4 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751891 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/openxml4j/opc/AllOpenXML4JTests.java | 2 -- .../AllOpenXML4JComplianceTests.java | 33 ------------------- .../TestOPCComplianceCoreProperties.java | 21 ++++++++++-- .../TestOPCCompliancePackageModel.java | 12 +++++-- .../compliance/TestOPCCompliancePartName.java | 19 +++++++++-- 5 files changed, 44 insertions(+), 43 deletions(-) delete mode 100644 src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java index a0bcb5fe85..7b98afd972 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java @@ -17,7 +17,6 @@ package org.apache.poi.openxml4j.opc; -import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -32,7 +31,6 @@ import org.junit.runners.Suite; , TestPackageThumbnail.class , TestPackagingURIHelper.class , TestRelationships.class - , AllOpenXML4JComplianceTests.class }) public final class AllOpenXML4JTests { } diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java deleted file mode 100644 index 3139b9451e..0000000000 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/* ==================================================================== - 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 junit.framework.Test; -import junit.framework.TestSuite; - -public final class AllOpenXML4JComplianceTests { - - public static Test suite() { - TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName()); - suite.addTestSuite(TestOPCCompliancePartName.class); - suite.addTestSuite(TestOPCComplianceCoreProperties.class); - suite.addTestSuite(TestOPCCompliancePackageModel.class); - return suite; - } - -} diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index 08dd9baa52..311db55c22 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -17,6 +17,12 @@ package org.apache.poi.openxml4j.opc.compliance; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -37,9 +43,9 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.util.IOUtils; import org.apache.poi.util.TempFile; +import org.junit.Test; import junit.framework.AssertionFailedError; -import junit.framework.TestCase; /** * Test core properties Open Packaging Convention compliance. @@ -73,8 +79,9 @@ import junit.framework.TestCase; * * @author Julien Chable */ -public final class TestOPCComplianceCoreProperties extends TestCase { +public final class TestOPCComplianceCoreProperties { + @Test public void testCorePropertiesPart() { OPCPackage pkg; try { @@ -106,6 +113,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.1 rule. */ + @Test public void testOnlyOneCorePropertiesPart() throws Exception { // We have relaxed this check, so we can read the file anyway try { @@ -141,6 +149,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.1 rule. */ + @Test public void testOnlyOneCorePropertiesPart_AddRelationship() { InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"); OPCPackage pkg; @@ -169,6 +178,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.1 rule. */ + @Test public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException { String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx"; OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath()); @@ -189,6 +199,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.2 rule. */ + @Test 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); @@ -197,6 +208,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.3 rule. */ + @Test 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: and Consumers shall consider a document element that violates this constraint to be an error.", msg); @@ -205,6 +217,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.4 rule. */ + @Test 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); @@ -213,6 +226,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.5 rule. */ + @Test public void testLimitedXSITypeAttribute_NotPresent() { String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx"); assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg); @@ -221,6 +235,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { /** * Test M4.5 rule. */ + @Test 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', but had 'W3CDTF' !", msg); @@ -230,6 +245,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { * Document with no core properties - testing at the OPC level, * saving into a new stream */ + @Test public void testNoCoreProperties_saveNew() throws Exception { String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx"; OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath()); @@ -277,6 +293,7 @@ public final class TestOPCComplianceCoreProperties extends TestCase { * Document with no core properties - testing at the OPC level, * from a temp-file, saving in-place */ + @Test public void testNoCoreProperties_saveInPlace() throws Exception { String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx"; diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java index 768612525b..7cf9e4b95e 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java @@ -17,9 +17,9 @@ package org.apache.poi.openxml4j.opc.compliance; -import java.io.IOException; +import static org.junit.Assert.fail; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -31,6 +31,7 @@ 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; +import org.junit.Test; /** * Test Open Packaging Convention package model compliance. @@ -40,13 +41,14 @@ import org.apache.poi.openxml4j.opc.TargetMode; * * @author Julien Chable */ -public class TestOPCCompliancePackageModel extends TestCase { +public class TestOPCCompliancePackageModel { /** * 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] */ + @Test public void testPartNameDerivationAdditionFailure() { OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx"); try { @@ -72,6 +74,7 @@ public class TestOPCCompliancePackageModel extends TestCase { * part name derived from another part name by appending segments to it. * [M1.11] */ + @Test public void testPartNameDerivationReadingFailure() throws IOException { String filename = "OPCCompliance_DerivedPartNameFAIL.docx"; try { @@ -89,6 +92,7 @@ public class TestOPCCompliancePackageModel extends TestCase { * implementers shall neither create nor recognize packages with equivalent * part names. */ + @Test public void testAddPackageAlreadyAddFailure() throws Exception { OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); PackagePartName name1 = null; @@ -113,6 +117,7 @@ public class TestOPCCompliancePackageModel extends TestCase { * implementers shall neither create nor recognize packages with equivalent * part names. */ + @Test public void testAddPackageAlreadyAddFailure2() throws Exception { OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); PackagePartName partName = null; @@ -138,6 +143,7 @@ public class TestOPCCompliancePackageModel extends TestCase { * the attempt to create such a relationship and shall treat any such * relationship as invalid. */ + @Test public void testAddRelationshipRelationshipsPartFailure() { OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx"); PackagePartName name1 = null; diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java index 5ecad86970..e7754ed576 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java @@ -17,14 +17,17 @@ package org.apache.poi.openxml4j.opc.compliance; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.net.URI; import java.net.URISyntaxException; -import junit.framework.TestCase; - import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.PackagingURIHelper; +import org.junit.Test; /** * Test part name Open Packaging Convention compliance. @@ -77,13 +80,14 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper; * * @author Julien Chable */ -public final class TestOPCCompliancePartName extends TestCase { +public final class TestOPCCompliancePartName { /** * Test some common invalid names. * * A segment shall not contain percent-encoded unreserved characters. [M1.8] */ + @Test public void testInvalidPartNames() { String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." }; for (String s : invalidNames) { @@ -102,6 +106,7 @@ public final class TestOPCCompliancePartName extends TestCase { /** * Test some common valid names. */ + @Test public void testValidPartNames() throws URISyntaxException { String[] validNames = { "/xml/item1.xml", "/document.xml", "/a/%D1%86.xml" }; @@ -113,6 +118,7 @@ public final class TestOPCCompliancePartName extends TestCase { /** * A part name shall not be empty. [M1.1] */ + @Test public void testEmptyPartNameFailure() throws URISyntaxException { try { PackagingURIHelper.createPartName(new URI("")); @@ -129,6 +135,7 @@ public final class TestOPCCompliancePartName extends TestCase { * * A segment shall include at least one non-dot character. [M1.10] */ + @Test public void testPartNameWithInvalidSegmentsFailure() { String[] invalidNames = { "//document.xml", "//word/document.xml", "/word//document.rels", "/word//rels//document.rels", @@ -148,6 +155,7 @@ public final class TestOPCCompliancePartName extends TestCase { * A segment shall not hold any characters other than ipchar (RFC 3987) characters. * [M1.6]. */ + @Test public void testPartNameWithNonPCharCharacters() { String[] validNames = { "/doc&.xml" }; try { @@ -164,6 +172,7 @@ public final class TestOPCCompliancePartName extends TestCase { /** * A segment shall not contain percent-encoded unreserved characters [M1.8]. */ + @Test public void testPartNameWithUnreservedEncodedCharactersFailure() { String[] invalidNames = { "/a/docum%65nt.xml" }; try { @@ -180,6 +189,7 @@ public final class TestOPCCompliancePartName extends TestCase { /** * A part name shall start with a forward slash ('/') character. [M1.4] */ + @Test public void testPartNameStartsWithAForwardSlashFailure() throws URISyntaxException { try { @@ -193,6 +203,7 @@ public final class TestOPCCompliancePartName extends TestCase { /** * A part name shall not have a forward slash as the last character. [M1.5] */ + @Test public void testPartNameEndsWithAForwardSlashFailure() throws URISyntaxException { try { @@ -207,6 +218,7 @@ public final class TestOPCCompliancePartName extends TestCase { * Part name equivalence is determined by comparing part names as * case-insensitive ASCII strings. [M1.12] */ + @Test public void testPartNameComparaison() throws Exception { String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" }; String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml", "/rels/.rels" }; @@ -225,6 +237,7 @@ public final class TestOPCCompliancePartName extends TestCase { * * All the comparisons MUST FAIL ! */ + @Test public void testPartNameComparaisonFailure() throws Exception { String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" }; String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml", "/rels/rels" };