]> source.dussan.org Git - poi.git/commitdiff
convert OPC Compliance unit tests to junit4
authorJaven O'Neal <onealj@apache.org>
Fri, 8 Jul 2016 12:07:20 +0000 (12:07 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 8 Jul 2016 12:07:20 +0000 (12:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751891 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java

index a0bcb5fe856c5b27b7cf34edb6907ba522354629..7b98afd9726ea3c3278a2d06dcf0e85467d7687a 100644 (file)
@@ -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 (file)
index 3139b94..0000000
+++ /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;
-       }
-
-}
index 08dd9baa52614c4bc33d9ac24e027f93aa8352e1..311db55c22ec1619b793b2dcd8e0d4b92359fa25 100644 (file)
 
 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: <dcterms:created> and <dcterms:modified> 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";
 
index 768612525b4330f0851836e8c6f8653f6f025100..7cf9e4b95e5d08f4c57866baa87b31d12192ebe6 100644 (file)
@@ -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;
index 5ecad86970d6863ece1a2699f77b974e61794f2e..e7754ed576349b92dd542683364f461b48a2a49a 100644 (file)
 
 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" };