]> source.dussan.org Git - poi.git/commitdiff
Improvements to OpenXML4J unit tests. Fixed class names. Refactored code for opening...
authorJosh Micich <josh@apache.org>
Thu, 5 Feb 2009 05:07:23 +0000 (05:07 +0000)
committerJosh Micich <josh@apache.org>
Thu, 5 Feb 2009 05:07:23 +0000 (05:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@741002 13f79535-47bb-0310-9956-ffa450edef68

25 files changed:
build.xml
src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/TestCore.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllTests.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestCreatePackageOUTPUT.docx [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageRemovePartRecursiveTMP.docx [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageThumbnailOUTPUT.docx [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllTests.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_CoreProperties.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PackageModel.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PartName.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllOpenXML4JInternalTests.java [new file with mode: 0755]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllTests.java [deleted file]
src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/TestContentTypeManager.java
src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java

index c04db3d0e09040f026760fa37039657511d412df..bf960aa88eb3d01f9c4d214637c0ffe658c7c589 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -797,7 +797,6 @@ under the License.
             <sysproperty key="OOXML.testdata.path" file="${ooxml.src.test}/org/apache/poi/ooxml/data"/> 
             <sysproperty key="openxml4j.compliance.input" file="${ooxml.src.test}/org/apache/poi/openxml4j/opc/compliance/input"/> 
             <sysproperty key="openxml4j.testdata.input" file="${ooxml.src.test}/org/apache/poi/openxml4j/opc/INPUT"/> 
-            <sysproperty key="openxml4j.testdata.output" file="${ooxml.src.test}/org/apache/poi/openxml4j/opc/OUTPUT"/> 
             <sysproperty key="java.awt.headless" value="true"/>
             <formatter type="plain"/>
             <formatter type="xml"/>
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java b/src/ooxml/testcases/org/apache/poi/openxml4j/OpenXML4JTestDataSamples.java
new file mode 100755 (executable)
index 0000000..62291d3
--- /dev/null
@@ -0,0 +1,148 @@
+/* ====================================================================
+   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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * Centralises logic for finding/opening sample files for ooxml4j unit tests 
+ * 
+ * @author jmicich
+ */
+public final class OpenXML4JTestDataSamples {
+
+       private static final String IN_DIR_PROP_NAME = "openxml4j.testdata.input";
+       private static final String COMP_IN_DIR_PROP_NAME = "openxml4j.compliance.input";
+       
+       private static File _sampleInputDir;
+       private static File _sampleOutputDir;
+       private static File _complianceSampleInputDir;
+
+       private OpenXML4JTestDataSamples() {
+               // no instances of this class
+       }
+       
+       public static InputStream openSampleStream(String sampleFileName) {
+               File f = getSampleFile(sampleFileName);
+               try {
+                       return new FileInputStream(f);
+               } catch (FileNotFoundException e) {
+                       throw new RuntimeException(e);
+               }
+       }
+       public static String getSampleFileName(String sampleFileName) {
+               // TODO - investigate allowing read/write access for package opened on stream
+               return getSampleFile(sampleFileName).getAbsolutePath();
+       }
+       
+       public static File getSampleFile(String sampleFileName) {
+               File dir = getSampleInputDir();
+               File f = new File(dir, sampleFileName);
+               if (!f.exists()) {
+                       throw new RuntimeException("Specified sample file '" 
+                                       + f.getAbsolutePath() + "' does not exist");
+               }
+               if (f.isDirectory()) {
+                       throw new RuntimeException("Specified sample file '" 
+                                       + f.getAbsolutePath() + "' is a directory");
+               }
+               return f;
+       }
+       
+       public static File getOutputFile(String outputFileName) {
+               File dir = getSampleOutputDir();
+               return new File(dir, outputFileName);
+       }
+
+
+       public static InputStream openComplianceSampleStream(String sampleFileName) {
+               File f = getComplianceSampleFile(sampleFileName);
+               try {
+                       return new FileInputStream(f);
+               } catch (FileNotFoundException e) {
+                       throw new RuntimeException(e);
+               }
+       }
+       private static File getComplianceSampleFile(String sampleFileName) {
+               File dir = getComplianceSampleInputDir();
+               File f = new File(dir, sampleFileName);
+               if (!f.exists()) {
+                       throw new RuntimeException("Specified sample file '" 
+                                       + f.getAbsolutePath() + "' does not exist");
+               }
+               if (f.isDirectory()) {
+                       throw new RuntimeException("Specified sample file '" 
+                                       + f.getAbsolutePath() + "' is a directory");
+               }
+               return f;
+       }
+       public static String getComplianceSampleFileName(String sampleFileName) {
+               return getComplianceSampleFile(sampleFileName).getAbsolutePath();
+       }
+       private static File getComplianceSampleInputDir() {
+               if (_complianceSampleInputDir == null) {
+                       _complianceSampleInputDir = getAndCheckDirByProperty(COMP_IN_DIR_PROP_NAME);
+               }
+               return _complianceSampleInputDir;
+       }
+
+       
+       private static File getSampleInputDir() {
+               if (_sampleInputDir == null) {
+                       _sampleInputDir = getAndCheckDirByProperty(IN_DIR_PROP_NAME);
+               }
+               return _sampleInputDir;
+       }
+
+       private static File getAndCheckDirByProperty(String propName) {
+               String dirName = System.getProperty(propName);
+               File dir = new File(dirName);
+               if (!dir.exists()) {
+                       throw new RuntimeException("Specified '" + propName + "' directory: '"
+                                       + dirName + "' does not exist");
+               }
+               if (!dir.isDirectory()) {
+                       throw new RuntimeException("Specified '" + propName + "' directory: '"
+                                       + dirName + "' is a not a proper directory");
+               }
+               return dir;
+       }
+
+       private static File getSampleOutputDir() {
+               if (_sampleOutputDir == null) {
+            File dir = new File(System.getProperty("java.io.tmpdir"), "poifiles");
+                       if (dir.exists()) {
+                       if (!dir.isDirectory()) {
+                               throw new RuntimeException("Specified output directory: '"
+                                               + dir.getAbsolutePath() + "' is a not a proper directory");
+                       }
+                       } else {
+                               if (!dir.mkdirs()) {
+                                       throw new RuntimeException("Failed to create directory: '"
+                                                       + dir.getAbsolutePath() + "'");
+                               }
+                       }
+                       _sampleOutputDir = dir;
+               }
+               return _sampleOutputDir;
+       }
+
+}
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/TestCore.java b/src/ooxml/testcases/org/apache/poi/openxml4j/TestCore.java
deleted file mode 100755 (executable)
index 26bf0ce..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j;\r
-\r
-import java.io.File;\r
-\r
-import org.apache.log4j.Logger;\r
-import org.apache.log4j.PropertyConfigurator;\r
-\r
-/**\r
- * Core helper for tests.\r
- * \r
- * @author Julien Chable\r
- * @version 1.0\r
- */\r
-public class TestCore {\r
-\r
-       private String testRootPath; // Test root path\r
-\r
-       /**\r
-        * All sample document are normally located at this place.\r
-        */\r
-       private static String pathRootProject; // Project root path\r
-\r
-       /**\r
-        * Demo logger\r
-        */\r
-       private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");\r
-\r
-       static {\r
-               pathRootProject = System.getProperty("user.dir") + File.separator + "bin";\r
-\r
-               // Log4j configuration\r
-               //PropertyConfigurator.configure(pathRootProject + File.separator\r
-               //              + "config.log4j");\r
-       }\r
-\r
-       /**\r
-        * Constructor. Initialize the demo.\r
-        * \r
-        */\r
-       public TestCore(Class cl) {\r
-               init(cl);\r
-       }\r
-\r
-       /**\r
-        * Initialize the test root path\r
-        */\r
-       public void init(Class cl) {\r
-               String packageName = cl.getPackage().getName();\r
-               // replace . by /\r
-               String sep = File.separator;\r
-               if (sep.equals("\\")) {\r
-                       sep = "\\\\";\r
-               }\r
-               testRootPath = pathRootProject + File.separator\r
-                               + packageName.replaceAll("\\.", sep)\r
-                               + File.separator;\r
-       }\r
-\r
-       // Accessors\r
-\r
-       /**\r
-        * Gets the test root path.\r
-        * \r
-        * @return The test root path.\r
-        */\r
-       public String getTestRootPath() {\r
-               return testRootPath;\r
-       }\r
-\r
-       /**\r
-        * Sets the test root path.\r
-        * \r
-        * @param testRoot\r
-        */\r
-       public void setTestRootPath(String testRoot) {\r
-               this.testRootPath = testRoot;\r
-       }\r
-\r
-       /**\r
-        * @return the logger\r
-        */\r
-       public static Logger getLogger() {\r
-               return logger;\r
-       }\r
-}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java
new file mode 100755 (executable)
index 0000000..12bc388
--- /dev/null
@@ -0,0 +1,44 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc;\r
+\r
+import junit.framework.Test;\r
+import junit.framework.TestSuite;\r
+\r
+import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;\r
+import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests;\r
+\r
+public final class AllOpenXML4JTests {\r
+\r
+       public static Test suite() {\r
+               \r
+               TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName());\r
+               suite.addTestSuite(TestContentType.class);\r
+               suite.addTestSuite(TestFileHelper.class);\r
+               suite.addTestSuite(TestListParts.class);\r
+               suite.addTestSuite(TestPackage.class);\r
+               suite.addTestSuite(TestPackageCoreProperties.class);\r
+               suite.addTestSuite(TestPackagePartName.class);\r
+               suite.addTestSuite(TestPackageThumbnail.class);\r
+               suite.addTestSuite(TestPackagingURIHelper.class);\r
+               suite.addTestSuite(TestRelationships.class);\r
+               suite.addTest(AllOpenXML4JComplianceTests.suite());\r
+               suite.addTest(AllOpenXML4JInternalTests.suite());\r
+               return suite;\r
+       }\r
+}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllTests.java
deleted file mode 100755 (executable)
index 4b2cc45..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-public class AllTests {\r
-\r
-       public static Test suite() {\r
-               TestSuite suite = new TestSuite(\r
-                               "Functional tests for org.apache.poi.openxml4j.opc");\r
-               suite.addTestSuite(TestListParts.class);\r
-               suite.addTestSuite(TestFileHelper.class);\r
-               suite.addTestSuite(TestPackage.class);\r
-               suite.addTestSuite(TestPackageCoreProperties.class);\r
-               suite.addTestSuite(TestPackagePartName.class);\r
-               suite.addTestSuite(TestPackagingURIHelper.class);\r
-               suite.addTestSuite(TestContentType.class);\r
-               suite.addTestSuite(TestPackageThumbnail.class);\r
-               return suite;\r
-       }\r
-}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestCreatePackageOUTPUT.docx b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestCreatePackageOUTPUT.docx
deleted file mode 100755 (executable)
index 3da1dae..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestCreatePackageOUTPUT.docx and /dev/null differ
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageRemovePartRecursiveTMP.docx b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageRemovePartRecursiveTMP.docx
deleted file mode 100755 (executable)
index c8c43dc..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageRemovePartRecursiveTMP.docx and /dev/null differ
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageThumbnailOUTPUT.docx b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageThumbnailOUTPUT.docx
deleted file mode 100755 (executable)
index a41daa5..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/OUTPUT/TestPackageThumbnailOUTPUT.docx and /dev/null differ
index 359c02faf87d3b5d8649760da9b7c1178cbb094a..c35f57833ea21d8312a26bfcdb40155241cc65ec 100755 (executable)
 \r
 package org.apache.poi.openxml4j.opc;\r
 \r
-import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
 import java.util.TreeMap;\r
 \r
 import junit.framework.TestCase;\r
 \r
+import org.apache.log4j.Logger;\r
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;\r
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.opc.Package;\r
-import org.apache.poi.openxml4j.opc.PackageAccess;\r
-import org.apache.poi.openxml4j.opc.PackagePart;\r
-import org.apache.poi.openxml4j.opc.PackagePartName;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
 \r
-import org.apache.poi.openxml4j.TestCore;\r
+public final class TestListParts extends TestCase {\r
+       private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");\r
 \r
-public class TestListParts extends TestCase {\r
+       private TreeMap<PackagePartName, String> expectedValues;\r
 \r
-       TestCore testCore = new TestCore(this.getClass());\r
-\r
-       TreeMap<PackagePartName, String> expectedValues;\r
-\r
-       TreeMap<PackagePartName, String> values;\r
+       private TreeMap<PackagePartName, String> values;\r
 \r
        @Override\r
        protected void setUp() throws Exception {\r
@@ -86,13 +81,17 @@ public class TestListParts extends TestCase {
         * List all parts of a package.\r
         */\r
        public void testListParts() throws InvalidFormatException {\r
-               String filepath = System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "sample.docx";\r
+               InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.docx");\r
 \r
-               Package p = Package.open(filepath, PackageAccess.READ);\r
+               Package p;\r
+               try {\r
+                       p = Package.open(is);\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
                for (PackagePart part : p.getParts()) {\r
                        values.put(part.getPartName(), part.getContentType());\r
-                       TestCore.getLogger().debug(part.getPartName());\r
+                       logger.debug(part.getPartName());\r
                }\r
 \r
                // Compare expected values with values return by the package\r
index 8d4e3313e2fca541b1ff00f0252d506d5697555b..0b95bbe1190ca36cbf5627e300c404cda8167b55 100755 (executable)
@@ -30,33 +30,28 @@ import java.util.TreeMap;
 \r
 import junit.framework.TestCase;\r
 \r
+import org.apache.log4j.Logger;\r
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;\r
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
+import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;\r
+import org.apache.poi.openxml4j.opc.internal.FileHelper;\r
 import org.dom4j.Document;\r
 import org.dom4j.DocumentHelper;\r
 import org.dom4j.Element;\r
 import org.dom4j.Namespace;\r
 import org.dom4j.QName;\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;\r
-import org.apache.poi.openxml4j.opc.internal.FileHelper;\r
 \r
-import org.apache.poi.openxml4j.TestCore;\r
-\r
-public class TestPackage extends TestCase {\r
-\r
-       TestCore testCore = new TestCore(this.getClass());\r
+public final class TestPackage extends TestCase {\r
+       private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");\r
 \r
        /**\r
         * Test that just opening and closing the file doesn't alter the document.\r
         */\r
        public void testOpenSave() throws Exception {\r
-               File originalFile = new File(System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "TestPackageCommon.docx");\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output")\r
-                               + File.separator + "TestPackageOpenSaveTMP.docx");\r
-               assertTrue("Source file " + originalFile + " doesn't exist!", originalFile.exists());\r
-\r
-               Package p = Package.open(originalFile.getAbsolutePath(),\r
-                               PackageAccess.READ_WRITE);\r
+               String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");\r
+\r
+               Package p = Package.open(originalFile, PackageAccess.READ_WRITE);\r
                p.save(targetFile.getAbsoluteFile());\r
 \r
                // Compare the original and newly saved document\r
@@ -70,8 +65,7 @@ public class TestPackage extends TestCase {
         *  the correct default content types\r
         */\r
        public void testCreateGetsContentTypes() throws Exception {\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator \r
-                               + "TestCreatePackageTMP.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx");\r
                \r
                // Zap the target file, in case of an earlier run\r
                if(targetFile.exists()) targetFile.delete();\r
@@ -103,11 +97,9 @@ public class TestPackage extends TestCase {
         * Test package creation.\r
         */\r
        public void testCreatePackageAddPart() throws Exception {\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator\r
-                               + "TestCreatePackageTMP.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx");\r
 \r
-               File expectedFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator\r
-                               + "TestCreatePackageOUTPUT.docx");\r
+               File expectedFileFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageOUTPUT.docx");\r
 \r
                // Zap the target file, in case of an earlier run\r
                if(targetFile.exists()) targetFile.delete();\r
@@ -208,14 +200,11 @@ public class TestPackage extends TestCase {
         * Test package opening.\r
         */\r
        public void testOpenPackage() throws Exception {\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output")\r
-                               + File.separator + "TestOpenPackageTMP.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestOpenPackageTMP.docx");\r
 \r
-               File inputFile = new File(System.getProperty("openxml4j.testdata.input")\r
-                               + File.separator + "TestOpenPackageINPUT.docx");\r
+               File inputFile = OpenXML4JTestDataSamples.getSampleFile("TestOpenPackageINPUT.docx");\r
 \r
-               File expectedFile = new File(System.getProperty("openxml4j.testdata.output")\r
-                + File.separator + "TestOpenPackageOUTPUT.docx");\r
+               File expectedFile = OpenXML4JTestDataSamples.getOutputFile("TestOpenPackageOUTPUT.docx");\r
 \r
                // Copy the input file in the output directory\r
                FileHelper.copyFile(inputFile, targetFile);\r
@@ -271,14 +260,10 @@ public class TestPackage extends TestCase {
         *  to a file\r
         */\r
        public void testSaveToOutputStream() throws Exception {\r
-               File originalFile = new File(System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "TestPackageCommon.docx");\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator\r
-                + "TestPackageOpenSaveTMP.docx");\r
-               assertTrue("Source file " + originalFile + " doesn't exist!", originalFile.exists());\r
-\r
-               Package p = Package.open(originalFile.getAbsolutePath(),\r
-                               PackageAccess.READ_WRITE);\r
+               String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");\r
+\r
+               Package p = Package.open(originalFile, PackageAccess.READ_WRITE);\r
                FileOutputStream fout = new FileOutputStream(targetFile);\r
                p.save(fout);\r
                fout.close();\r
@@ -295,9 +280,7 @@ public class TestPackage extends TestCase {
         *  reading from a file\r
         */\r
        public void testOpenFromInputStream() throws Exception {\r
-               File originalFile = new File(System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "TestPackageCommon.docx");\r
-               assertTrue("Source file " + originalFile + " doesn't exist!", originalFile.exists());\r
+               String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");\r
                \r
                FileInputStream finp = new FileInputStream(originalFile);\r
                \r
@@ -313,18 +296,14 @@ public class TestPackage extends TestCase {
        }\r
 \r
     /**\r
-     * TODO: fix and unable\r
+     * TODO: fix and enable\r
      */\r
     public void disabled_testRemovePartRecursive() throws Exception {\r
-               File originalFile = new File(System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "TestPackageCommon.docx");\r
-               File targetFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator\r
-                               + "TestPackageRemovePartRecursiveOUTPUT.docx");\r
-               File tempFile = new File(System.getProperty("openxml4j.testdata.output") + File.separator\r
-                               + "TestPackageRemovePartRecursiveTMP.docx");\r
-\r
-               Package p = Package.open(originalFile.getAbsolutePath(),\r
-                               PackageAccess.READ_WRITE);\r
+               String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");\r
+               File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");\r
+               File tempFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveTMP.docx");\r
+\r
+               Package p = Package.open(originalFile, PackageAccess.READ_WRITE);\r
                p.removePartRecursive(PackagingURIHelper.createPartName(new URI(\r
                                "/word/document.xml")));\r
                p.save(tempFile.getAbsoluteFile());\r
@@ -372,8 +351,7 @@ public class TestPackage extends TestCase {
                                                                .createPartName("/word/webSettings.xml"),\r
                                                "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml");\r
 \r
-               String filepath = System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "sample.docx";\r
+               String filepath =  OpenXML4JTestDataSamples.getSampleFileName("sample.docx");\r
 \r
                Package p = Package.open(filepath, PackageAccess.READ_WRITE);\r
                // Remove the core part\r
@@ -381,7 +359,7 @@ public class TestPackage extends TestCase {
 \r
                for (PackagePart part : p.getParts()) {\r
                        values.put(part.getPartName(), part.getContentType());\r
-                       TestCore.getLogger().debug(part.getPartName());\r
+                       logger.debug(part.getPartName());\r
                }\r
 \r
                // Compare expected values with values return by the package\r
@@ -389,7 +367,7 @@ public class TestPackage extends TestCase {
                        assertNotNull(values.get(partName));\r
                        assertEquals(expectedValues.get(partName), values.get(partName));\r
                }\r
-               // Don't save modfications\r
+               // Don't save modifications\r
                p.revert();\r
        }\r
        \r
@@ -411,8 +389,7 @@ public class TestPackage extends TestCase {
                                .createPartName("/docProps/core.xml"),\r
                                "application/vnd.openxmlformats-package.core-properties+xml");\r
 \r
-               String filepath = System.getProperty("openxml4j.testdata.input") + File.separator\r
-                               + "sample.docx";\r
+               String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");\r
 \r
                Package p = Package.open(filepath, PackageAccess.READ_WRITE);\r
                // Remove the core part\r
@@ -420,7 +397,7 @@ public class TestPackage extends TestCase {
 \r
                for (PackagePart part : p.getParts()) {\r
                        values.put(part.getPartName(), part.getContentType());\r
-                       TestCore.getLogger().debug(part.getPartName());\r
+                       logger.debug(part.getPartName());\r
                }\r
 \r
                // Compare expected values with values return by the package\r
@@ -428,7 +405,7 @@ public class TestPackage extends TestCase {
                        assertNotNull(values.get(partName));\r
                        assertEquals(expectedValues.get(partName), values.get(partName));\r
                }\r
-               // Don't save modfications\r
+               // Don't save modifications\r
                p.revert();\r
        }\r
        \r
index acb7cd84f452d6ec08e610f1734f0e6c4fef9f25..54e21b89d3810c203145978ed80fe3543b56f9ea 100755 (executable)
 package org.apache.poi.openxml4j.opc;\r
 \r
 import java.io.File;\r
+import java.io.IOException;\r
 import java.text.ParsePosition;\r
 import java.text.SimpleDateFormat;\r
 import java.util.Date;\r
 \r
 import junit.framework.TestCase;\r
 \r
+import org.apache.log4j.Logger;\r
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;\r
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;\r
 import org.apache.poi.openxml4j.util.Nullable;\r
 \r
-import org.apache.poi.openxml4j.TestCore;\r
-import org.apache.log4j.Logger;\r
-\r
-public class TestPackageCoreProperties extends TestCase {\r
-\r
-       TestCore testCore = new TestCore(this.getClass());\r
+public final class TestPackageCoreProperties extends TestCase {\r
 \r
        /**\r
         * Test package core properties getters.\r
@@ -41,13 +39,14 @@ public class TestPackageCoreProperties extends TestCase {
        public void testGetProperties() {\r
                try {\r
                        // Open the package\r
-                       Package p = Package.open(System.getProperty("openxml4j.testdata.input") + File.separator\r
-                                       + "TestPackageCoreProperiesGetters.docx",\r
-                                       PackageAccess.READ);\r
+                       Package p = Package.open(OpenXML4JTestDataSamples.openSampleStream("TestPackageCoreProperiesGetters.docx"));\r
                        compareProperties(p);\r
                        p.revert();\r
                } catch (OpenXML4JException e) {\r
                        Logger.getLogger("org.apache.poi.openxml4j.demo").debug(e.getMessage());\r
+                       throw new RuntimeException(e);\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
                }\r
        }\r
 \r
@@ -55,11 +54,9 @@ public class TestPackageCoreProperties extends TestCase {
         * Test package core properties setters.\r
         */\r
        public void testSetProperties() throws Exception {\r
-               String inputPath = System.getProperty("openxml4j.testdata.input")\r
-                               + File.separator + "TestPackageCoreProperiesSetters.docx";\r
+               String inputPath = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCoreProperiesSetters.docx");\r
 \r
-               String outputFilename = System.getProperty("openxml4j.testdata.input")\r
-                               + File.separator + "TestPackageCoreProperiesSettersOUTPUT.docx";\r
+               File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageCoreProperiesSettersOUTPUT.docx");\r
 \r
                // Open package\r
                Package p = Package.open(inputPath, PackageAccess.READ_WRITE);\r
@@ -86,14 +83,13 @@ public class TestPackageCoreProperties extends TestCase {
                props.setSubjectProperty("MySubject");\r
                props.setVersionProperty("2");\r
                // Save the package in the output directory\r
-               p.save(new File(outputFilename));\r
+               p.save(outputFile);\r
 \r
                // Open the newly created file to check core properties saved values.\r
-               File fOut = new File(outputFilename);\r
-               Package p2 = Package.open(outputFilename, PackageAccess.READ);\r
+               Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ);\r
                compareProperties(p2);\r
                p2.revert();\r
-               fOut.delete();\r
+               outputFile.delete();\r
        }\r
 \r
        private void compareProperties(Package p) throws InvalidFormatException {\r
index bbf5402f4863eb6b1f09673da25b3ca6f20234f2..a7b9e7b6f660025dbdfd16be0d938a25e86e0ee2 100755 (executable)
@@ -21,47 +21,37 @@ import java.io.File;
 \r
 import junit.framework.TestCase;\r
 \r
-import org.apache.poi.openxml4j.opc.Package;\r
-import org.apache.poi.openxml4j.opc.PackageAccess;\r
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;\r
-\r
-import org.apache.poi.openxml4j.TestCore;\r
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;\r
 \r
 /**\r
  * Test the addition of thumbnail in a package.\r
  * \r
  * @author Julien Chable\r
  */\r
-public class TestPackageThumbnail extends TestCase {\r
-\r
-       TestCore testCore = new TestCore(this.getClass());\r
+public final class TestPackageThumbnail extends TestCase {\r
 \r
        /**\r
         * Test package addThumbnail() method.\r
         */\r
        public void testSetProperties() throws Exception {\r
-               String inputPath = System.getProperty("openxml4j.testdata.input")\r
-                               + File.separator + "TestPackageThumbnail.docx";\r
+               String inputPath = OpenXML4JTestDataSamples.getSampleFileName("TestPackageThumbnail.docx");\r
 \r
-               String imagePath = System.getProperty("openxml4j.testdata.input")\r
-                               + File.separator + "thumbnail.jpg";\r
+               String imagePath = OpenXML4JTestDataSamples.getSampleFileName("thumbnail.jpg");\r
 \r
-               String outputFilename = System.getProperty("openxml4j.testdata.output")\r
-                               + File.separator + "TestPackageThumbnailOUTPUT.docx";\r
+               File outputFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageThumbnailOUTPUT.docx");\r
 \r
                // Open package\r
                Package p = Package.open(inputPath, PackageAccess.READ_WRITE);\r
                p.addThumbnail(imagePath);\r
                // Save the package in the output directory\r
-               p.save(new File(outputFilename));\r
+               p.save(outputFile);\r
 \r
                // Open the newly created file to check core properties saved values.\r
-               File fOut = new File(outputFilename);\r
-               Package p2 = Package.open(outputFilename, PackageAccess.READ);\r
+               Package p2 = Package.open(outputFile.getAbsolutePath(), PackageAccess.READ);\r
                if (p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL)\r
                                .size() == 0)\r
                        fail("Thumbnail not added to the package !");\r
                p2.revert();\r
-               //fOut.delete();\r
+               outputFile.delete();\r
        }\r
 }\r
index 3ca1281033822c942d780d3c1678c5f400a031c6..972bd268a3f988eedeeb964903fd5e9e4baf12de 100755 (executable)
@@ -19,32 +19,23 @@ package org.apache.poi.openxml4j.opc;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.openxml4j.opc.Package;
-import org.apache.poi.openxml4j.opc.PackageAccess;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
-import org.apache.poi.openxml4j.opc.TargetMode;
-
-import org.apache.poi.openxml4j.TestCore;
+import org.apache.log4j.Logger;
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 
 
 public class TestRelationships extends TestCase {
-       public static final String HYPERLINK_REL_TYPE =
+       private static final String HYPERLINK_REL_TYPE =
                "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
-       public static final String COMMENTS_REL_TYPE =
+       private static final String COMMENTS_REL_TYPE =
                "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
-       public static final String SHEET_WITH_COMMENTS =
+       private static final String SHEET_WITH_COMMENTS =
                "/xl/worksheets/sheet1.xml";
 
-    TestCore testCore = new TestCore(this.getClass());
+       private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");
 
     /**
      * Test relationships are correctly loaded. This at the moment fails (as of r499)
@@ -53,10 +44,9 @@ public class TestRelationships extends TestCase {
      * really look also for not yet loaded parts.
      */
     public void testLoadRelationships() throws Exception {
-        String filepath = System.getProperty("openxml4j.testdata.input") + File.separator
-            + "sample.xlsx";
-        Package pkg = Package.open(filepath, PackageAccess.READ);
-        TestCore.getLogger().debug("1: " + pkg);
+        InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
+        Package pkg = Package.open(is);
+        logger.debug("1: " + pkg);
         PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
         PackageRelationship coreDocRelationship = rels.getRelationship(0);
         PackagePart corePart = pkg.getPart(coreDocRelationship);
@@ -75,10 +65,8 @@ public class TestRelationships extends TestCase {
      *  type, then grab from within there by id
      */
     public void testFetchFromCollection() throws Exception {
-        String filepath = System.getProperty("openxml4j.testdata.input") + File.separator
-               + "ExcelWithHyperlinks.xlsx";
-       
-        Package pkg = Package.open(filepath, PackageAccess.READ);
+        InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
+        Package pkg = Package.open(is);
         PackagePart sheet = pkg.getPart(
                        PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
         assertNotNull(sheet);
@@ -118,10 +106,8 @@ public class TestRelationships extends TestCase {
      *  external hyperlinks. Check we can load these ok.
      */
     public void testLoadExcelHyperlinkRelations() throws Exception {
-        String filepath = System.getProperty("openxml4j.testdata.input") + File.separator
-               + "ExcelWithHyperlinks.xlsx";
-               
-           Package pkg = Package.open(filepath, PackageAccess.READ);
+        InputStream is = OpenXML4JTestDataSamples.openSampleStream("ExcelWithHyperlinks.xlsx");
+        Package pkg = Package.open(is);
            PackagePart sheet = pkg.getPart(
                        PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
            assertNotNull(sheet);
@@ -150,13 +136,11 @@ public class TestRelationships extends TestCase {
     
     /*
      * Excel uses relations on sheets to store the details of 
-     *  external hyperlinks. Check we can create these ok
+     *  external hyperlinks. Check we can create these OK
      *  then still read them later
      */
     public void testCreateExcelHyperlinkRelations() throws Exception {
-        String filepath = System.getProperty("openxml4j.testdata.input") + File.separator
-               + "ExcelWithHyperlinks.xlsx";
-               
+       String filepath = OpenXML4JTestDataSamples.getSampleFileName("ExcelWithHyperlinks.xlsx");
            Package pkg = Package.open(filepath, PackageAccess.READ_WRITE);
            PackagePart sheet = pkg.getPart(
                        PackagingURIHelper.createPartName(SHEET_WITH_COMMENTS));
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
new file mode 100755 (executable)
index 0000000..cd990cc
--- /dev/null
@@ -0,0 +1,33 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc.compliance;\r
+\r
+import junit.framework.Test;\r
+import junit.framework.TestSuite;\r
+\r
+public class AllOpenXML4JComplianceTests {\r
+\r
+       public static Test suite() {\r
+               TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName());\r
+               suite.addTestSuite(TestOPCCompliancePartName.class);\r
+               suite.addTestSuite(TestOPCComplianceCoreProperties.class);\r
+               suite.addTestSuite(TestOPCCompliancePackageModel.class);\r
+               return suite;\r
+       }\r
+\r
+}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllTests.java
deleted file mode 100755 (executable)
index 56974b0..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.compliance;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-public class AllTests {\r
-\r
-       public static Test suite() {\r
-               TestSuite suite = new TestSuite(\r
-                               "Test for test.org.apache.poi.openxml4j.opc.compliance");\r
-               // $JUnit-BEGIN$\r
-               suite.addTestSuite(OPCCompliance_PartName.class);\r
-               suite.addTestSuite(OPCCompliance_CoreProperties.class);\r
-               suite.addTestSuite(OPCCompliance_PackageModel.class);\r
-               // $JUnit-END$\r
-               return suite;\r
-       }\r
-\r
-}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_CoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_CoreProperties.java
deleted file mode 100755 (executable)
index a26fd30..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.compliance;\r
-\r
-import java.io.File;\r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
-\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.exceptions.InvalidOperationException;\r
-import org.apache.poi.openxml4j.opc.ContentTypes;\r
-import org.apache.poi.openxml4j.opc.Package;\r
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-import org.apache.poi.openxml4j.opc.TargetMode;\r
-\r
-import org.apache.poi.openxml4j.TestCore;\r
-import junit.framework.TestCase;\r
-\r
-/**\r
- * Test core properties Open Packaging Convention compliance.\r
- * \r
- * M4.1: The format designer shall specify and the format producer shall create\r
- * at most one core properties relationship for a package. A format consumer\r
- * shall consider more than one core properties relationship for a package to be\r
- * an error. If present, the relationship shall target the Core Properties part.\r
- * \r
- * M4.2: The format designer shall not specify and the format producer shall not\r
- * create Core Properties that use the Markup Compatibility namespace as defined\r
- * in Annex F, "Standard Namespaces and Content Types". A format consumer shall\r
- * consider the use of the Markup Compatibility namespace to be an error.\r
- * \r
- * M4.3: Producers shall not create a document element that contains refinements\r
- * to the Dublin Core elements, except for the two specified in the schema:\r
- * <dcterms:created> and <dcterms:modified> Consumers shall consider a document\r
- * element that violates this constraint to be an error.\r
- * \r
- * M4.4: Producers shall not create a document element that contains the\r
- * xml:lang attribute. Consumers shall consider a document element that violates\r
- * this constraint to be an error.\r
- * \r
- * M4.5: Producers shall not create a document element that contains the\r
- * xsi:type attribute, except for a <dcterms:created> or <dcterms:modified>\r
- * element where the xsi:type attribute shall be present and shall hold the\r
- * value dcterms:W3CDTF, where dcterms is the namespace prefix of the Dublin\r
- * Core namespace. Consumers shall consider a document element that violates\r
- * this constraint to be an error.\r
- * \r
- * @author Julien Chable\r
- * @version 1.0\r
- */\r
-public class OPCCompliance_CoreProperties extends TestCase {\r
-\r
-       TestCore testCore = new TestCore(this.getClass());\r
-\r
-       public void testCorePropertiesPart() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-               } catch (InvalidFormatException e) {\r
-                       fail("OPC compliance failure: the core properties is considered as invalid than it's not !");\r
-               } finally {\r
-                       pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.1 rule.\r
-        */\r
-       public void testOnlyOneCorePropertiesPart() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.1 -> A format consumer shall consider more than one core properties relationship for a package to be an error.");\r
-               } catch (InvalidFormatException e) {\r
-                       // DO nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.1 rule.\r
-        */\r
-       public void testOnlyOneCorePropertiesPart_AddRelationship() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.testdata.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";\r
-                       pkg = Package.open(filepath);\r
-                       pkg.addRelationship(PackagingURIHelper.createPartName(new URI(\r
-                                       "/docProps/core2.xml")), TargetMode.INTERNAL,\r
-                                       PackageRelationshipTypes.CORE_PROPERTIES);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.1 -> A format consumer shall consider more than one core properties relationship for a package to be an error.");\r
-               } catch (InvalidOperationException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } catch (URISyntaxException e) {\r
-                       // Should never happen\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.1 rule.\r
-        */\r
-       public void testOnlyOneCorePropertiesPart_AddPart() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.testdata.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";\r
-                       pkg = Package.open(filepath);\r
-                       pkg.createPart(PackagingURIHelper.createPartName(new URI(\r
-                                       "/docProps/core2.xml")), ContentTypes.CORE_PROPERTIES_PART);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.1 -> A format consumer shall consider more than one core properties relationship for a package to be an error.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } catch (InvalidOperationException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } catch (URISyntaxException e) {\r
-                       // Should never happen\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.2 rule.\r
-        */\r
-       public void testDoNotUseCompatibilityMarkup() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_DoNotUseCompatibilityMarkupFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.2 -> A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.3 rule.\r
-        */\r
-       public void testDCTermsNamespaceLimitedUse() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_DCTermsNamespaceLimitedUseFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: 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.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.4 rule.\r
-        */\r
-       public void testUnauthorizedXMLLangAttribute() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.4 -> 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.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.5 rule.\r
-        */\r
-       public void testLimitedXSITypeAttribute_NotPresent() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_LimitedXSITypeAttribute_NotPresentFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.5 -> 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.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test M4.5 rule.\r
-        */\r
-       public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {\r
-               Package pkg = null;\r
-               try {\r
-                       String filepath = System.getProperty("openxml4j.compliance.input")\r
-                                       + File.separator\r
-                                       + "OPCCompliance_CoreProperties_LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx";\r
-                       pkg = Package.open(filepath);\r
-                       // Normally must thrown an InvalidFormatException exception.\r
-                       fail("OPC compliance failure: M4.5 -> 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.");\r
-               } catch (InvalidFormatException e) {\r
-                       // Do nothing, it's the normal behavior\r
-               } finally {\r
-                       if (pkg != null)\r
-                               pkg.revert();\r
-               }\r
-       }\r
-}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PackageModel.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PackageModel.java
deleted file mode 100755 (executable)
index f54c294..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.compliance;\r
-\r
-import java.io.File;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.exceptions.InvalidOperationException;\r
-import org.apache.poi.openxml4j.opc.ContentTypes;\r
-import org.apache.poi.openxml4j.opc.Package;\r
-import org.apache.poi.openxml4j.opc.PackagePartName;\r
-import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-import org.apache.poi.openxml4j.opc.TargetMode;\r
-\r
-import org.apache.poi.openxml4j.TestCore;\r
-\r
-/**\r
- * Test Open Packaging Convention package model compliance.\r
- * \r
- * M1.11 : A package implementer shall neither create nor recognize a part with\r
- * a part name derived from another part name by appending segments to it.\r
- * \r
- * @author Julien Chable\r
- */\r
-public class OPCCompliance_PackageModel extends TestCase {\r
-\r
-       TestCore testCore = new TestCore(this.getClass());\r
-\r
-       public OPCCompliance_PackageModel(String name) {\r
-               super(name);\r
-       }\r
-\r
-       /**\r
-        * A package implementer shall neither create nor recognize a part with a\r
-        * part name derived from another part name by appending segments to it.\r
-        * [M1.11]\r
-        */\r
-       public void testPartNameDerivationAdditionFailure() {\r
-               Package pkg = null;\r
-               try {\r
-                       pkg = Package.create("TODELETEIFEXIST.docx");\r
-                       PackagePartName name = PackagingURIHelper\r
-                                       .createPartName("/word/document.xml");\r
-                       PackagePartName nameDerived = PackagingURIHelper\r
-                                       .createPartName("/word/document.xml/image1.gif");\r
-                       pkg.createPart(name, ContentTypes.XML);\r
-                       pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);\r
-               } catch (InvalidOperationException e) {\r
-                       pkg.revert();\r
-                       return;\r
-               } catch (InvalidFormatException e) {\r
-                       fail(e.getMessage());\r
-               }\r
-               fail("A package implementer shall neither create nor recognize a part with a"\r
-                               + " part name derived from another part name by appending segments to it."\r
-                               + " [M1.11]");\r
-       }\r
-\r
-       /**\r
-        * A package implementer shall neither create nor recognize a part with a\r
-        * part name derived from another part name by appending segments to it.\r
-        * [M1.11]\r
-        */\r
-       public void testPartNameDerivationReadingFailure() {\r
-               String filepath = System.getProperty("openxml4j.compliance.input")\r
-                               + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";\r
-               try {\r
-                       Package.open(filepath);\r
-               } catch (InvalidFormatException e) {\r
-                       return;\r
-               }\r
-               fail("A package implementer shall neither create nor recognize a part with a"\r
-                               + " part name derived from another part name by appending segments to it."\r
-                               + " [M1.11]");\r
-       }\r
-\r
-       /**\r
-        * Rule M1.12 : Packages shall not contain equivalent part names and package\r
-        * implementers shall neither create nor recognize packages with equivalent\r
-        * part names.\r
-        */\r
-       public void testAddPackageAlreadyAddFailure() throws Exception {\r
-               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
-               PackagePartName name1 = null;\r
-               PackagePartName name2 = null;\r
-               try {\r
-                       name1 = PackagingURIHelper.createPartName("/word/document.xml");\r
-                       name2 = PackagingURIHelper.createPartName("/word/document.xml");\r
-               } catch (InvalidFormatException e) {\r
-                       throw new Exception(e.getMessage());\r
-               }\r
-               pkg.createPart(name1, ContentTypes.XML);\r
-               try {\r
-                       pkg.createPart(name2, ContentTypes.XML);\r
-               } catch (InvalidOperationException e) {\r
-                       return;\r
-               }\r
-               fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");\r
-       }\r
-\r
-       /**\r
-        * Rule M1.12 : Packages shall not contain equivalent part names and package\r
-        * implementers shall neither create nor recognize packages with equivalent\r
-        * part names.\r
-        */\r
-       public void testAddPackageAlreadyAddFailure2() throws Exception {\r
-               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
-               PackagePartName partName = null;\r
-               try {\r
-                       partName = PackagingURIHelper.createPartName("/word/document.xml");\r
-               } catch (InvalidFormatException e) {\r
-                       throw new Exception(e.getMessage());\r
-               }\r
-               pkg.createPart(partName, ContentTypes.XML);\r
-               try {\r
-                       pkg.createPart(partName, ContentTypes.XML);\r
-               } catch (InvalidOperationException e) {\r
-                       return;\r
-               }\r
-               fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");\r
-       }\r
-\r
-       /**\r
-        * Try to add a relationship to a relationship part.\r
-        * \r
-        * Check rule M1.25: The Relationships part shall not have relationships to\r
-        * any other part. Package implementers shall enforce this requirement upon\r
-        * the attempt to create such a relationship and shall treat any such\r
-        * relationship as invalid.\r
-        */\r
-       public void testAddRelationshipRelationshipsPartFailure() {\r
-               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
-               PackagePartName name1 = null;\r
-               try {\r
-                       name1 = PackagingURIHelper\r
-                                       .createPartName("/test/_rels/document.xml.rels");\r
-               } catch (InvalidFormatException e) {\r
-                       fail("This exception should never happen !");\r
-               }\r
-\r
-               try {\r
-                       pkg.addRelationship(name1, TargetMode.INTERNAL,\r
-                                       PackageRelationshipTypes.CORE_DOCUMENT);\r
-               } catch (InvalidOperationException e) {\r
-                       return;\r
-               }\r
-               fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");\r
-       }\r
-}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PartName.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/OPCCompliance_PartName.java
deleted file mode 100755 (executable)
index 80f6be7..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.compliance;\r
-\r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
-import org.apache.poi.openxml4j.opc.PackagePartName;\r
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-\r
-/**\r
- * Test part name Open Packaging Convention compliance.\r
- * \r
- * (Open Packaging Convention 8.1.1 Part names) :\r
- * \r
- * The part name grammar is defined as follows:\r
- * \r
- * part_name = 1*( "/" segment )\r
- * \r
- * segment = 1*( pchar )\r
- * \r
- * pchar is defined in RFC 3986.\r
- * \r
- * The part name grammar implies the following constraints. The package\r
- * implementer shall neither create any part that violates these constraints nor\r
- * retrieve any data from a package as a part if the purported part name\r
- * violates these constraints.\r
- * \r
- * A part name shall not be empty. [M1.1]\r
- * \r
- * A part name shall not have empty segments. [M1.3]\r
- * \r
- * A part name shall start with a forward slash ("/") character. [M1.4]\r
- * \r
- * A part name shall not have a forward slash as the last character. [M1.5]\r
- * \r
- * A segment shall not hold any characters other than pchar characters. [M1.6]\r
- * \r
- * Part segments have the following additional constraints. The package\r
- * implementer shall neither create any part with a part name comprised of a\r
- * segment that violates these constraints nor retrieve any data from a package\r
- * as a part if the purported part name contains a segment that violates these\r
- * constraints.\r
- * \r
- * A segment shall not contain percent-encoded forward slash ("/"), or backward\r
- * slash ("\") characters. [M1.7]\r
- * \r
- * A segment shall not contain percent-encoded unreserved characters. [M1.8]\r
- * \r
- * A segment shall not end with a dot (".") character. [M1.9]\r
- * \r
- * A segment shall include at least one non-dot character. [M1.10]\r
- * \r
- * A package implementer shall neither create nor recognize a part with a part\r
- * name derived from another part name by appending segments to it. [M1.11]\r
- * \r
- * Part name equivalence is determined by comparing part names as\r
- * case-insensitive ASCII strings. [M1.12]\r
- * \r
- * @author Julien Chable\r
- * @version 1.0\r
- */\r
-public class OPCCompliance_PartName extends TestCase {\r
-\r
-       public OPCCompliance_PartName(String name) {\r
-               super(name);\r
-       }\r
-\r
-       /**\r
-        * Test some common invalid names.\r
-        * \r
-        * A segment shall not contain percent-encoded unreserved characters. [M1.8]\r
-        */\r
-       public void testInvalidPartNames() {\r
-               String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };\r
-               for (String s : invalidNames) {\r
-                       URI uri = null;\r
-                       try {\r
-                               uri = new URI(s);\r
-                       } catch (URISyntaxException e) {\r
-                               assertTrue(s == "[Content_Types].xml");\r
-                               continue;\r
-                       }\r
-                       assertFalse("This part name SHOULD NOT be valid: " + s,\r
-                                       PackagingURIHelper.isValidPartName(uri));\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Test some common valid names.\r
-        */\r
-       public void testValidPartNames() throws URISyntaxException {\r
-               String[] validNames = { "/xml/item1.xml", "/document.xml",\r
-                               "/a/%D1%86.xml" };\r
-               for (String s : validNames)\r
-                       assertTrue("This part name SHOULD be valid: " + s,\r
-                                       PackagingURIHelper.isValidPartName(new URI(s)));\r
-       }\r
-\r
-       /**\r
-        * A part name shall not be empty. [M1.1]\r
-        */\r
-       public void testEmptyPartNameFailure() throws URISyntaxException {\r
-               try {\r
-                       PackagingURIHelper.createPartName(new URI(""));\r
-                       fail("A part name shall not be empty. [M1.1]");\r
-               } catch (InvalidFormatException e) {\r
-                       // Normal behaviour\r
-               }\r
-       }\r
-\r
-       /**\r
-        * A part name shall not have empty segments. [M1.3]\r
-        * \r
-        * A segment shall not end with a dot ('.') character. [M1.9]\r
-        * \r
-        * A segment shall include at least one non-dot character. [M1.10]\r
-        */\r
-       public void testPartNameWithInvalidSegmentsFailure() {\r
-               String[] invalidNames = { "//document.xml", "//word/document.xml",\r
-                               "/word//document.rels", "/word//rels//document.rels",\r
-                               "/xml./doc.xml", "/document.", "/./document.xml",\r
-                               "/word/./doc.rels", "/%2F/document.xml" };\r
-               try {\r
-                       for (String s : invalidNames)\r
-                               assertFalse(\r
-                                               "A part name shall not have empty segments. [M1.3]",\r
-                                               PackagingURIHelper.isValidPartName(new URI(s)));\r
-               } catch (URISyntaxException e) {\r
-                       fail();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * A segment shall not hold any characters other than pchar characters.\r
-        * [M1.6].\r
-        */\r
-       public void testPartNameWithNonPCharCharacters() {\r
-               String[] invalidNames = { "/doc�&.xml" };\r
-               try {\r
-                       for (String s : invalidNames)\r
-                               assertTrue(\r
-                                               "A segment shall not contain non pchar characters [M1.6] : "\r
-                                                               + s, PackagingURIHelper\r
-                                                               .isValidPartName(new URI(s)));\r
-               } catch (URISyntaxException e) {\r
-                       fail();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * A segment shall not contain percent-encoded unreserved characters [M1.8].\r
-        */\r
-       public void testPartNameWithUnreservedEncodedCharactersFailure() {\r
-               String[] invalidNames = { "/a/docum%65nt.xml" };\r
-               try {\r
-                       for (String s : invalidNames)\r
-                               assertFalse(\r
-                                               "A segment shall not contain percent-encoded unreserved characters [M1.8] : "\r
-                                                               + s, PackagingURIHelper\r
-                                                               .isValidPartName(new URI(s)));\r
-               } catch (URISyntaxException e) {\r
-                       fail();\r
-               }\r
-       }\r
-\r
-       /**\r
-        * A part name shall start with a forward slash ('/') character. [M1.4]\r
-        */\r
-       public void testPartNameStartsWithAForwardSlashFailure()\r
-                       throws URISyntaxException {\r
-               try {\r
-                       PackagingURIHelper.createPartName(new URI("document.xml"));\r
-                       fail("A part name shall start with a forward slash ('/') character. [M1.4]");\r
-               } catch (InvalidFormatException e) {\r
-                       // Normal behaviour\r
-               }\r
-       }\r
-\r
-       /**\r
-        * A part name shall not have a forward slash as the last character. [M1.5]\r
-        */\r
-       public void testPartNameEndsWithAForwardSlashFailure()\r
-                       throws URISyntaxException {\r
-               try {\r
-                       PackagingURIHelper.createPartName(new URI("/document.xml/"));\r
-                       fail("A part name shall not have a forward slash as the last character. [M1.5]");\r
-               } catch (InvalidFormatException e) {\r
-                       // Normal behaviour\r
-               }\r
-\r
-       }\r
-\r
-       /**\r
-        * Part name equivalence is determined by comparing part names as\r
-        * case-insensitive ASCII strings. [M1.12]\r
-        */\r
-       public void testPartNameComparaison() throws Exception {\r
-               String[] partName1 = { "/word/document.xml", "/docProps/core.xml",\r
-                               "/rels/.rels" };\r
-               String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml",\r
-                               "/rels/.rels" };\r
-               for (int i = 0; i < partName1.length || i < partName2.length; ++i) {\r
-                       PackagePartName p1 = PackagingURIHelper\r
-                                       .createPartName(partName1[i]);\r
-                       PackagePartName p2 = PackagingURIHelper\r
-                                       .createPartName(partName2[i]);\r
-                       assertTrue(p1.equals(p2));\r
-                       assertTrue(p1.compareTo(p2) == 0);\r
-                       assertTrue(p1.hashCode() == p2.hashCode());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Part name equivalence is determined by comparing part names as\r
-        * case-insensitive ASCII strings. [M1.12].\r
-        * \r
-        * All the comparaisons MUST FAIL !\r
-        */\r
-       public void testPartNameComparaisonFailure() throws Exception {\r
-               String[] partName1 = { "/word/document.xml", "/docProps/core.xml",\r
-                               "/rels/.rels" };\r
-               String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml",\r
-                               "/rels/rels" };\r
-               for (int i = 0; i < partName1.length || i < partName2.length; ++i) {\r
-                       PackagePartName p1 = PackagingURIHelper\r
-                                       .createPartName(partName1[i]);\r
-                       PackagePartName p2 = PackagingURIHelper\r
-                                       .createPartName(partName2[i]);\r
-                       assertFalse(p1.equals(p2));\r
-                       assertFalse(p1.compareTo(p2) == 0);\r
-                       assertFalse(p1.hashCode() == p2.hashCode());\r
-               }\r
-       }\r
-}\r
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
new file mode 100755 (executable)
index 0000000..d2cb8f6
--- /dev/null
@@ -0,0 +1,208 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc.compliance;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
+\r
+import junit.framework.AssertionFailedError;\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;\r
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
+import org.apache.poi.openxml4j.exceptions.InvalidOperationException;\r
+import org.apache.poi.openxml4j.opc.ContentTypes;\r
+import org.apache.poi.openxml4j.opc.Package;\r
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;\r
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
+import org.apache.poi.openxml4j.opc.TargetMode;\r
+\r
+/**\r
+ * Test core properties Open Packaging Convention compliance.\r
+ * \r
+ * M4.1: The format designer shall specify and the format producer shall create\r
+ * at most one core properties relationship for a package. A format consumer\r
+ * shall consider more than one core properties relationship for a package to be\r
+ * an error. If present, the relationship shall target the Core Properties part.\r
+ * \r
+ * M4.2: The format designer shall not specify and the format producer shall not\r
+ * create Core Properties that use the Markup Compatibility namespace as defined\r
+ * in Annex F, "Standard Namespaces and Content Types". A format consumer shall\r
+ * consider the use of the Markup Compatibility namespace to be an error.\r
+ * \r
+ * M4.3: Producers shall not create a document element that contains refinements\r
+ * to the Dublin Core elements, except for the two specified in the schema:\r
+ * <dcterms:created> and <dcterms:modified> Consumers shall consider a document\r
+ * element that violates this constraint to be an error.\r
+ * \r
+ * M4.4: Producers shall not create a document element that contains the\r
+ * xml:lang attribute. Consumers shall consider a document element that violates\r
+ * this constraint to be an error.\r
+ * \r
+ * M4.5: Producers shall not create a document element that contains the\r
+ * xsi:type attribute, except for a <dcterms:created> or <dcterms:modified>\r
+ * element where the xsi:type attribute shall be present and shall hold the\r
+ * value dcterms:W3CDTF, where dcterms is the namespace prefix of the Dublin\r
+ * Core namespace. Consumers shall consider a document element that violates\r
+ * this constraint to be an error.\r
+ * \r
+ * @author Julien Chable\r
+ */\r
+public final class TestOPCComplianceCoreProperties extends TestCase {\r
+\r
+       public void testCorePropertiesPart() {\r
+               Package pkg;\r
+               try {\r
+                       InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");\r
+                       pkg = Package.open(is);\r
+               } catch (InvalidFormatException e) {\r
+                       throw new RuntimeException(e);\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               pkg.revert();\r
+       }\r
+\r
+       private static String extractInvalidFormatMessage(String sampleNameSuffix) {\r
+\r
+               InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);\r
+               Package pkg;\r
+               try {\r
+                       pkg = Package.open(is);\r
+               } catch (InvalidFormatException e) {\r
+                       // expected during successful test\r
+                       return e.getMessage();\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               pkg.revert();\r
+               // Normally must thrown an InvalidFormatException exception.\r
+               throw new AssertionFailedError("expected OPC compliance exception was not thrown");\r
+       }\r
+       \r
+       /**\r
+        * Test M4.1 rule.\r
+        */\r
+       public void testOnlyOneCorePropertiesPart() {\r
+               String msg = extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");\r
+               assertEquals("OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !", msg);\r
+       }\r
+       \r
+       private static URI createURI(String text) {\r
+               try {\r
+                       return new URI(text);\r
+               } catch (URISyntaxException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Test M4.1 rule.\r
+        */\r
+       public void testOnlyOneCorePropertiesPart_AddRelationship() {\r
+               InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");\r
+               Package pkg;\r
+               try {\r
+                       pkg = Package.open(is);\r
+               } catch (InvalidFormatException e) {\r
+                       throw new RuntimeException(e);\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               URI partUri = createURI("/docProps/core2.xml");\r
+               try {\r
+                       pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,\r
+                                       PackageRelationshipTypes.CORE_PROPERTIES);\r
+                       fail("expected OPC compliance exception was not thrown");\r
+               } catch (InvalidFormatException e) {\r
+                       throw new RuntimeException(e);\r
+               } catch (InvalidOperationException e) {\r
+                       // expected during successful test\r
+                       assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());\r
+               }\r
+               pkg.revert();\r
+       }\r
+\r
+       /**\r
+        * Test M4.1 rule.\r
+        */\r
+       public void testOnlyOneCorePropertiesPart_AddPart() {\r
+               String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");\r
+               Package pkg = null;\r
+               try {\r
+                       pkg = Package.open(sampleFileName);\r
+               } catch (InvalidFormatException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               \r
+               URI partUri = createURI("/docProps/core2.xml");\r
+               try {\r
+                       pkg.createPart(PackagingURIHelper.createPartName(partUri),\r
+                                       ContentTypes.CORE_PROPERTIES_PART);\r
+                       fail("expected OPC compliance exception was not thrown");\r
+               } catch (InvalidFormatException e) {\r
+                       throw new RuntimeException(e);\r
+               } catch (InvalidOperationException e) {\r
+                       // expected during successful test\r
+                       assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());\r
+               }\r
+               pkg.revert();\r
+       }\r
+\r
+       /**\r
+        * Test M4.2 rule.\r
+        */\r
+       public void testDoNotUseCompatibilityMarkup() {\r
+               String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");\r
+               assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);\r
+       }\r
+\r
+       /**\r
+        * Test M4.3 rule.\r
+        */\r
+       public void testDCTermsNamespaceLimitedUse() {\r
+               String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");\r
+               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);\r
+       }\r
+\r
+       /**\r
+        * Test M4.4 rule.\r
+        */\r
+       public void testUnauthorizedXMLLangAttribute() {\r
+               String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");\r
+               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);\r
+       }\r
+\r
+       /**\r
+        * Test M4.5 rule.\r
+        */\r
+       public void testLimitedXSITypeAttribute_NotPresent() {\r
+               String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");\r
+               assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);\r
+       }\r
+\r
+       /**\r
+        * Test M4.5 rule.\r
+        */\r
+       public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {\r
+               String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");\r
+               assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF' !", msg);\r
+       }\r
+}\r
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
new file mode 100755 (executable)
index 0000000..f135b41
--- /dev/null
@@ -0,0 +1,162 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc.compliance;\r
+\r
+import java.io.File;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
+import org.apache.poi.openxml4j.exceptions.InvalidOperationException;\r
+import org.apache.poi.openxml4j.opc.ContentTypes;\r
+import org.apache.poi.openxml4j.opc.Package;\r
+import org.apache.poi.openxml4j.opc.PackagePartName;\r
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;\r
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
+import org.apache.poi.openxml4j.opc.TargetMode;\r
+\r
+/**\r
+ * Test Open Packaging Convention package model compliance.\r
+ * \r
+ * M1.11 : A package implementer shall neither create nor recognize a part with\r
+ * a part name derived from another part name by appending segments to it.\r
+ * \r
+ * @author Julien Chable\r
+ */\r
+public class TestOPCCompliancePackageModel extends TestCase {\r
+\r
+       public TestOPCCompliancePackageModel(String name) {\r
+               super(name);\r
+       }\r
+\r
+       /**\r
+        * A package implementer shall neither create nor recognize a part with a\r
+        * part name derived from another part name by appending segments to it.\r
+        * [M1.11]\r
+        */\r
+       public void testPartNameDerivationAdditionFailure() {\r
+               Package pkg = Package.create("TODELETEIFEXIST.docx");\r
+               try {\r
+                       PackagePartName name = PackagingURIHelper\r
+                                       .createPartName("/word/document.xml");\r
+                       PackagePartName nameDerived = PackagingURIHelper\r
+                                       .createPartName("/word/document.xml/image1.gif");\r
+                       pkg.createPart(name, ContentTypes.XML);\r
+                       pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);\r
+               } catch (InvalidOperationException e) {\r
+                       pkg.revert();\r
+                       return;\r
+               } catch (InvalidFormatException e) {\r
+                       fail(e.getMessage());\r
+               }\r
+               fail("A package implementer shall neither create nor recognize a part with a"\r
+                               + " part name derived from another part name by appending segments to it."\r
+                               + " [M1.11]");\r
+       }\r
+\r
+       /**\r
+        * A package implementer shall neither create nor recognize a part with a\r
+        * part name derived from another part name by appending segments to it.\r
+        * [M1.11]\r
+        */\r
+       public void testPartNameDerivationReadingFailure() {\r
+               String filepath = System.getProperty("openxml4j.compliance.input")\r
+                               + File.separator + "OPCCompliance_DerivedPartNameFAIL.docx";\r
+               try {\r
+                       Package.open(filepath);\r
+               } catch (InvalidFormatException e) {\r
+                       return;\r
+               }\r
+               fail("A package implementer shall neither create nor recognize a part with a"\r
+                               + " part name derived from another part name by appending segments to it."\r
+                               + " [M1.11]");\r
+       }\r
+\r
+       /**\r
+        * Rule M1.12 : Packages shall not contain equivalent part names and package\r
+        * implementers shall neither create nor recognize packages with equivalent\r
+        * part names.\r
+        */\r
+       public void testAddPackageAlreadyAddFailure() throws Exception {\r
+               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
+               PackagePartName name1 = null;\r
+               PackagePartName name2 = null;\r
+               try {\r
+                       name1 = PackagingURIHelper.createPartName("/word/document.xml");\r
+                       name2 = PackagingURIHelper.createPartName("/word/document.xml");\r
+               } catch (InvalidFormatException e) {\r
+                       throw new Exception(e.getMessage());\r
+               }\r
+               pkg.createPart(name1, ContentTypes.XML);\r
+               try {\r
+                       pkg.createPart(name2, ContentTypes.XML);\r
+               } catch (InvalidOperationException e) {\r
+                       return;\r
+               }\r
+               fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");\r
+       }\r
+\r
+       /**\r
+        * Rule M1.12 : Packages shall not contain equivalent part names and package\r
+        * implementers shall neither create nor recognize packages with equivalent\r
+        * part names.\r
+        */\r
+       public void testAddPackageAlreadyAddFailure2() throws Exception {\r
+               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
+               PackagePartName partName = null;\r
+               try {\r
+                       partName = PackagingURIHelper.createPartName("/word/document.xml");\r
+               } catch (InvalidFormatException e) {\r
+                       throw new Exception(e.getMessage());\r
+               }\r
+               pkg.createPart(partName, ContentTypes.XML);\r
+               try {\r
+                       pkg.createPart(partName, ContentTypes.XML);\r
+               } catch (InvalidOperationException e) {\r
+                       return;\r
+               }\r
+               fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");\r
+       }\r
+\r
+       /**\r
+        * Try to add a relationship to a relationship part.\r
+        * \r
+        * Check rule M1.25: The Relationships part shall not have relationships to\r
+        * any other part. Package implementers shall enforce this requirement upon\r
+        * the attempt to create such a relationship and shall treat any such\r
+        * relationship as invalid.\r
+        */\r
+       public void testAddRelationshipRelationshipsPartFailure() {\r
+               Package pkg = Package.create("DELETEIFEXISTS.docx");\r
+               PackagePartName name1 = null;\r
+               try {\r
+                       name1 = PackagingURIHelper\r
+                                       .createPartName("/test/_rels/document.xml.rels");\r
+               } catch (InvalidFormatException e) {\r
+                       fail("This exception should never happen !");\r
+               }\r
+\r
+               try {\r
+                       pkg.addRelationship(name1, TargetMode.INTERNAL,\r
+                                       PackageRelationshipTypes.CORE_DOCUMENT);\r
+               } catch (InvalidOperationException e) {\r
+                       return;\r
+               }\r
+               fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");\r
+       }\r
+}\r
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
new file mode 100755 (executable)
index 0000000..899c43e
--- /dev/null
@@ -0,0 +1,253 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc.compliance;\r
+\r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
+import org.apache.poi.openxml4j.opc.PackagePartName;\r
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
+\r
+/**\r
+ * Test part name Open Packaging Convention compliance.\r
+ * \r
+ * (Open Packaging Convention 8.1.1 Part names) :\r
+ * \r
+ * The part name grammar is defined as follows:\r
+ * \r
+ * part_name = 1*( "/" segment )\r
+ * \r
+ * segment = 1*( pchar )\r
+ * \r
+ * pchar is defined in RFC 3986.\r
+ * \r
+ * The part name grammar implies the following constraints. The package\r
+ * implementer shall neither create any part that violates these constraints nor\r
+ * retrieve any data from a package as a part if the purported part name\r
+ * violates these constraints.\r
+ * \r
+ * A part name shall not be empty. [M1.1]\r
+ * \r
+ * A part name shall not have empty segments. [M1.3]\r
+ * \r
+ * A part name shall start with a forward slash ("/") character. [M1.4]\r
+ * \r
+ * A part name shall not have a forward slash as the last character. [M1.5]\r
+ * \r
+ * A segment shall not hold any characters other than pchar characters. [M1.6]\r
+ * \r
+ * Part segments have the following additional constraints. The package\r
+ * implementer shall neither create any part with a part name comprised of a\r
+ * segment that violates these constraints nor retrieve any data from a package\r
+ * as a part if the purported part name contains a segment that violates these\r
+ * constraints.\r
+ * \r
+ * A segment shall not contain percent-encoded forward slash ("/"), or backward\r
+ * slash ("\") characters. [M1.7]\r
+ * \r
+ * A segment shall not contain percent-encoded unreserved characters. [M1.8]\r
+ * \r
+ * A segment shall not end with a dot (".") character. [M1.9]\r
+ * \r
+ * A segment shall include at least one non-dot character. [M1.10]\r
+ * \r
+ * A package implementer shall neither create nor recognize a part with a part\r
+ * name derived from another part name by appending segments to it. [M1.11]\r
+ * \r
+ * Part name equivalence is determined by comparing part names as\r
+ * case-insensitive ASCII strings. [M1.12]\r
+ * \r
+ * @author Julien Chable\r
+ * @version 1.0\r
+ */\r
+public class TestOPCCompliancePartName extends TestCase {\r
+\r
+       public TestOPCCompliancePartName(String name) {\r
+               super(name);\r
+       }\r
+\r
+       /**\r
+        * Test some common invalid names.\r
+        * \r
+        * A segment shall not contain percent-encoded unreserved characters. [M1.8]\r
+        */\r
+       public void testInvalidPartNames() {\r
+               String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };\r
+               for (String s : invalidNames) {\r
+                       URI uri = null;\r
+                       try {\r
+                               uri = new URI(s);\r
+                       } catch (URISyntaxException e) {\r
+                               assertTrue(s == "[Content_Types].xml");\r
+                               continue;\r
+                       }\r
+                       assertFalse("This part name SHOULD NOT be valid: " + s,\r
+                                       PackagingURIHelper.isValidPartName(uri));\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Test some common valid names.\r
+        */\r
+       public void testValidPartNames() throws URISyntaxException {\r
+               String[] validNames = { "/xml/item1.xml", "/document.xml",\r
+                               "/a/%D1%86.xml" };\r
+               for (String s : validNames)\r
+                       assertTrue("This part name SHOULD be valid: " + s,\r
+                                       PackagingURIHelper.isValidPartName(new URI(s)));\r
+       }\r
+\r
+       /**\r
+        * A part name shall not be empty. [M1.1]\r
+        */\r
+       public void testEmptyPartNameFailure() throws URISyntaxException {\r
+               try {\r
+                       PackagingURIHelper.createPartName(new URI(""));\r
+                       fail("A part name shall not be empty. [M1.1]");\r
+               } catch (InvalidFormatException e) {\r
+                       // Normal behaviour\r
+               }\r
+       }\r
+\r
+       /**\r
+        * A part name shall not have empty segments. [M1.3]\r
+        * \r
+        * A segment shall not end with a dot ('.') character. [M1.9]\r
+        * \r
+        * A segment shall include at least one non-dot character. [M1.10]\r
+        */\r
+       public void testPartNameWithInvalidSegmentsFailure() {\r
+               String[] invalidNames = { "//document.xml", "//word/document.xml",\r
+                               "/word//document.rels", "/word//rels//document.rels",\r
+                               "/xml./doc.xml", "/document.", "/./document.xml",\r
+                               "/word/./doc.rels", "/%2F/document.xml" };\r
+               try {\r
+                       for (String s : invalidNames)\r
+                               assertFalse(\r
+                                               "A part name shall not have empty segments. [M1.3]",\r
+                                               PackagingURIHelper.isValidPartName(new URI(s)));\r
+               } catch (URISyntaxException e) {\r
+                       fail();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * A segment shall not hold any characters other than pchar characters.\r
+        * [M1.6].\r
+        */\r
+       public void testPartNameWithNonPCharCharacters() {\r
+               String[] invalidNames = { "/doc�&.xml" };\r
+               try {\r
+                       for (String s : invalidNames)\r
+                               assertTrue(\r
+                                               "A segment shall not contain non pchar characters [M1.6] : "\r
+                                                               + s, PackagingURIHelper\r
+                                                               .isValidPartName(new URI(s)));\r
+               } catch (URISyntaxException e) {\r
+                       fail();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * A segment shall not contain percent-encoded unreserved characters [M1.8].\r
+        */\r
+       public void testPartNameWithUnreservedEncodedCharactersFailure() {\r
+               String[] invalidNames = { "/a/docum%65nt.xml" };\r
+               try {\r
+                       for (String s : invalidNames)\r
+                               assertFalse(\r
+                                               "A segment shall not contain percent-encoded unreserved characters [M1.8] : "\r
+                                                               + s, PackagingURIHelper\r
+                                                               .isValidPartName(new URI(s)));\r
+               } catch (URISyntaxException e) {\r
+                       fail();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * A part name shall start with a forward slash ('/') character. [M1.4]\r
+        */\r
+       public void testPartNameStartsWithAForwardSlashFailure()\r
+                       throws URISyntaxException {\r
+               try {\r
+                       PackagingURIHelper.createPartName(new URI("document.xml"));\r
+                       fail("A part name shall start with a forward slash ('/') character. [M1.4]");\r
+               } catch (InvalidFormatException e) {\r
+                       // Normal behaviour\r
+               }\r
+       }\r
+\r
+       /**\r
+        * A part name shall not have a forward slash as the last character. [M1.5]\r
+        */\r
+       public void testPartNameEndsWithAForwardSlashFailure()\r
+                       throws URISyntaxException {\r
+               try {\r
+                       PackagingURIHelper.createPartName(new URI("/document.xml/"));\r
+                       fail("A part name shall not have a forward slash as the last character. [M1.5]");\r
+               } catch (InvalidFormatException e) {\r
+                       // Normal behaviour\r
+               }\r
+\r
+       }\r
+\r
+       /**\r
+        * Part name equivalence is determined by comparing part names as\r
+        * case-insensitive ASCII strings. [M1.12]\r
+        */\r
+       public void testPartNameComparaison() throws Exception {\r
+               String[] partName1 = { "/word/document.xml", "/docProps/core.xml",\r
+                               "/rels/.rels" };\r
+               String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml",\r
+                               "/rels/.rels" };\r
+               for (int i = 0; i < partName1.length || i < partName2.length; ++i) {\r
+                       PackagePartName p1 = PackagingURIHelper\r
+                                       .createPartName(partName1[i]);\r
+                       PackagePartName p2 = PackagingURIHelper\r
+                                       .createPartName(partName2[i]);\r
+                       assertTrue(p1.equals(p2));\r
+                       assertTrue(p1.compareTo(p2) == 0);\r
+                       assertTrue(p1.hashCode() == p2.hashCode());\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Part name equivalence is determined by comparing part names as\r
+        * case-insensitive ASCII strings. [M1.12].\r
+        * \r
+        * All the comparaisons MUST FAIL !\r
+        */\r
+       public void testPartNameComparaisonFailure() throws Exception {\r
+               String[] partName1 = { "/word/document.xml", "/docProps/core.xml",\r
+                               "/rels/.rels" };\r
+               String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml",\r
+                               "/rels/rels" };\r
+               for (int i = 0; i < partName1.length || i < partName2.length; ++i) {\r
+                       PackagePartName p1 = PackagingURIHelper\r
+                                       .createPartName(partName1[i]);\r
+                       PackagePartName p2 = PackagingURIHelper\r
+                                       .createPartName(partName2[i]);\r
+                       assertFalse(p1.equals(p2));\r
+                       assertFalse(p1.compareTo(p2) == 0);\r
+                       assertFalse(p1.hashCode() == p2.hashCode());\r
+               }\r
+       }\r
+}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllOpenXML4JInternalTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllOpenXML4JInternalTests.java
new file mode 100755 (executable)
index 0000000..338f5df
--- /dev/null
@@ -0,0 +1,30 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.openxml4j.opc.internal;\r
+\r
+import junit.framework.Test;\r
+import junit.framework.TestSuite;\r
+\r
+public class AllOpenXML4JInternalTests {\r
+\r
+       public static Test suite() {\r
+               TestSuite suite = new TestSuite(AllOpenXML4JInternalTests.class.getName());\r
+               suite.addTestSuite(TestContentTypeManager.class);\r
+               return suite;\r
+       }\r
+}\r
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllTests.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/internal/AllTests.java
deleted file mode 100755 (executable)
index 25d140c..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-\r
-package org.apache.poi.openxml4j.opc.internal;\r
-\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
-\r
-public class AllTests {\r
-\r
-       public static Test suite() {\r
-               TestSuite suite = new TestSuite(\r
-                               "Test for test.org.apache.poi.openxml4j.opc.internal");\r
-               //$JUnit-BEGIN$\r
-               suite.addTestSuite(TestContentTypeManager.class);\r
-               //$JUnit-END$\r
-               return suite;\r
-       }\r
-}\r
index 6af3e6f544f0a714c926745ccc7e94df5d8def1c..d509272d7609404bb69d557443c4a73e0c3db172 100755 (executable)
@@ -21,15 +21,9 @@ import junit.framework.TestCase;
 \r
 import org.apache.poi.openxml4j.opc.PackagePartName;\r
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;\r
-import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;\r
-import org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager;\r
-\r
-import org.apache.poi.openxml4j.TestCore;\r
 \r
 public class TestContentTypeManager extends TestCase {\r
 \r
-       TestCore testCore = new TestCore(this.getClass());\r
-\r
        /**\r
         * Test the properties part content parsing.\r
         */\r
index d71565052871ea207deaaa922619bad05581ab49..c820f2c9bc176f30e423b20ee715ae88a6a2909a 100644 (file)
@@ -62,10 +62,10 @@ public final class TestExcelExtractor extends TestCase {
                assertEquals(
                                "Sheet1\n" +
                                "1000.0\t1.0\t5.0\n" +
-                               "2000.0\t2.0\t\n" +     
-                               "3000.0\t3.0\t\n" +
-                               "4000.0\t4.0\t\n" + 
-                               "5000.0\t5.0\t\n" +
+                               "2000.0\t2.0\n" +       
+                               "3000.0\t3.0\n" +
+                               "4000.0\t4.0\n" + 
+                               "5000.0\t5.0\n" +
                                "Sheet2\nSheet3\n", 
                                extractor.getText()
                );
@@ -75,10 +75,10 @@ public final class TestExcelExtractor extends TestCase {
                assertEquals(
                                "Sheet1\n" +
                                "1000.0\t1.0\tSUMIF(A1:A5,\">4000\",B1:B5)\n" +
-                               "2000.0\t2.0\t\n" +     
-                               "3000.0\t3.0\t\n" +
-                               "4000.0\t4.0\t\n" + 
-                               "5000.0\t5.0\t\n" +
+                               "2000.0\t2.0\n" +       
+                               "3000.0\t3.0\n" +
+                               "4000.0\t4.0\n" + 
+                               "5000.0\t5.0\n" +
                                "Sheet2\nSheet3\n", 
                                extractor.getText()
                );
@@ -196,15 +196,15 @@ public final class TestExcelExtractor extends TestCase {
                assertTrue(def.startsWith(
                                "Sheet1\n" +
                                "&[TAB]\t\n" +
-                               "Hello\t\n" +
-                               "11.0\t23.0\t\n"
+                               "Hello\n" +
+                               "11.0\t23.0\n"
                ));
                
                assertTrue(padded.startsWith(
                                "Sheet1\n" +
                                "&[TAB]\t\n" +
-                               "Hello\t\t\t\t\t\t\t\t\t\t\t\n" +
-                               "11.0\t\t\t23.0\t\t\t\t\t\t\t\t\n"
+                               "Hello\n" +
+                               "11.0\t\t\t23.0\n"
                ));
        }