package org.apache.poi.openxml4j.opc;
-import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
, TestPackageThumbnail.class
, TestPackagingURIHelper.class
, TestRelationships.class
- , AllOpenXML4JComplianceTests.class
})
public final class AllOpenXML4JTests {
}
+++ /dev/null
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.openxml4j.opc.compliance;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public final class AllOpenXML4JComplianceTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite(AllOpenXML4JComplianceTests.class.getName());
- suite.addTestSuite(TestOPCCompliancePartName.class);
- suite.addTestSuite(TestOPCComplianceCoreProperties.class);
- suite.addTestSuite(TestOPCCompliancePackageModel.class);
- return suite;
- }
-
-}
package org.apache.poi.openxml4j.opc.compliance;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
+import org.junit.Test;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
/**
* Test core properties Open Packaging Convention compliance.
*
* @author Julien Chable
*/
-public final class TestOPCComplianceCoreProperties extends TestCase {
+public final class TestOPCComplianceCoreProperties {
+ @Test
public void testCorePropertiesPart() {
OPCPackage pkg;
try {
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart() throws Exception {
// We have relaxed this check, so we can read the file anyway
try {
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart_AddRelationship() {
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
OPCPackage pkg;
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
/**
* Test M4.2 rule.
*/
+ @Test
public void testDoNotUseCompatibilityMarkup() {
String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");
assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);
/**
* Test M4.3 rule.
*/
+ @Test
public void testDCTermsNamespaceLimitedUse() {
String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");
assertEquals("OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.", msg);
/**
* Test M4.4 rule.
*/
+ @Test
public void testUnauthorizedXMLLangAttribute() {
String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");
assertEquals("OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.", msg);
/**
* Test M4.5 rule.
*/
+ @Test
public void testLimitedXSITypeAttribute_NotPresent() {
String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");
assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);
/**
* Test M4.5 rule.
*/
+ @Test
public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {
String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF', but had 'W3CDTF' !", msg);
* Document with no core properties - testing at the OPC level,
* saving into a new stream
*/
+ @Test
public void testNoCoreProperties_saveNew() throws Exception {
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
* Document with no core properties - testing at the OPC level,
* from a temp-file, saving in-place
*/
+ @Test
public void testNoCoreProperties_saveInPlace() throws Exception {
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
package org.apache.poi.openxml4j.opc.compliance;
-import java.io.IOException;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.junit.Test;
/**
* Test Open Packaging Convention package model compliance.
*
* @author Julien Chable
*/
-public class TestOPCCompliancePackageModel extends TestCase {
+public class TestOPCCompliancePackageModel {
/**
* A package implementer shall neither create nor recognize a part with a
* part name derived from another part name by appending segments to it.
* [M1.11]
*/
+ @Test
public void testPartNameDerivationAdditionFailure() {
OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
try {
* part name derived from another part name by appending segments to it.
* [M1.11]
*/
+ @Test
public void testPartNameDerivationReadingFailure() throws IOException {
String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
try {
* implementers shall neither create nor recognize packages with equivalent
* part names.
*/
+ @Test
public void testAddPackageAlreadyAddFailure() throws Exception {
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName name1 = null;
* implementers shall neither create nor recognize packages with equivalent
* part names.
*/
+ @Test
public void testAddPackageAlreadyAddFailure2() throws Exception {
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName partName = null;
* the attempt to create such a relationship and shall treat any such
* relationship as invalid.
*/
+ @Test
public void testAddRelationshipRelationshipsPartFailure() {
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName name1 = null;
package org.apache.poi.openxml4j.opc.compliance;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.net.URI;
import java.net.URISyntaxException;
-import junit.framework.TestCase;
-
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.junit.Test;
/**
* Test part name Open Packaging Convention compliance.
*
* @author Julien Chable
*/
-public final class TestOPCCompliancePartName extends TestCase {
+public final class TestOPCCompliancePartName {
/**
* Test some common invalid names.
*
* A segment shall not contain percent-encoded unreserved characters. [M1.8]
*/
+ @Test
public void testInvalidPartNames() {
String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };
for (String s : invalidNames) {
/**
* Test some common valid names.
*/
+ @Test
public void testValidPartNames() throws URISyntaxException {
String[] validNames = { "/xml/item1.xml", "/document.xml",
"/a/%D1%86.xml" };
/**
* A part name shall not be empty. [M1.1]
*/
+ @Test
public void testEmptyPartNameFailure() throws URISyntaxException {
try {
PackagingURIHelper.createPartName(new URI(""));
*
* A segment shall include at least one non-dot character. [M1.10]
*/
+ @Test
public void testPartNameWithInvalidSegmentsFailure() {
String[] invalidNames = { "//document.xml", "//word/document.xml",
"/word//document.rels", "/word//rels//document.rels",
* A segment shall not hold any characters other than ipchar (RFC 3987) characters.
* [M1.6].
*/
+ @Test
public void testPartNameWithNonPCharCharacters() {
String[] validNames = { "/doc&.xml" };
try {
/**
* A segment shall not contain percent-encoded unreserved characters [M1.8].
*/
+ @Test
public void testPartNameWithUnreservedEncodedCharactersFailure() {
String[] invalidNames = { "/a/docum%65nt.xml" };
try {
/**
* A part name shall start with a forward slash ('/') character. [M1.4]
*/
+ @Test
public void testPartNameStartsWithAForwardSlashFailure()
throws URISyntaxException {
try {
/**
* A part name shall not have a forward slash as the last character. [M1.5]
*/
+ @Test
public void testPartNameEndsWithAForwardSlashFailure()
throws URISyntaxException {
try {
* Part name equivalence is determined by comparing part names as
* case-insensitive ASCII strings. [M1.12]
*/
+ @Test
public void testPartNameComparaison() throws Exception {
String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml", "/rels/.rels" };
*
* All the comparisons MUST FAIL !
*/
+ @Test
public void testPartNameComparaisonFailure() throws Exception {
String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml", "/rels/rels" };