You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/08 12:07:20 UTC
svn commit: r1751891 - in
/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc: ./ compliance/
Author: onealj
Date: Fri Jul 8 12:07:20 2016
New Revision: 1751891
URL: http://svn.apache.org/viewvc?rev=1751891&view=rev
Log:
convert OPC Compliance unit tests to junit4
Removed:
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/AllOpenXML4JComplianceTests.java
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java?rev=1751891&r1=1751890&r2=1751891&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java Fri Jul 8 12:07:20 2016
@@ -17,7 +17,6 @@
package org.apache.poi.openxml4j.opc;
-import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -32,7 +31,6 @@ import org.junit.runners.Suite;
, TestPackageThumbnail.class
, TestPackagingURIHelper.class
, TestRelationships.class
- , AllOpenXML4JComplianceTests.class
})
public final class AllOpenXML4JTests {
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java?rev=1751891&r1=1751890&r2=1751891&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java Fri Jul 8 12:07:20 2016
@@ -17,6 +17,12 @@
package org.apache.poi.openxml4j.opc.compliance;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -37,9 +43,9 @@ import org.apache.poi.openxml4j.opc.Pack
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
+import org.junit.Test;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
/**
* Test core properties Open Packaging Convention compliance.
@@ -73,8 +79,9 @@ import junit.framework.TestCase;
*
* @author Julien Chable
*/
-public final class TestOPCComplianceCoreProperties extends TestCase {
+public final class TestOPCComplianceCoreProperties {
+ @Test
public void testCorePropertiesPart() {
OPCPackage pkg;
try {
@@ -106,6 +113,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart() throws Exception {
// We have relaxed this check, so we can read the file anyway
try {
@@ -141,6 +149,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart_AddRelationship() {
InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
OPCPackage pkg;
@@ -169,6 +178,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.1 rule.
*/
+ @Test
public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
@@ -189,6 +199,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.2 rule.
*/
+ @Test
public void testDoNotUseCompatibilityMarkup() {
String msg = extractInvalidFormatMessage("DoNotUseCompatibilityMarkupFAIL.docx");
assertEquals("OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.", msg);
@@ -197,6 +208,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.3 rule.
*/
+ @Test
public void testDCTermsNamespaceLimitedUse() {
String msg = extractInvalidFormatMessage("DCTermsNamespaceLimitedUseFAIL.docx");
assertEquals("OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.", msg);
@@ -205,6 +217,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.4 rule.
*/
+ @Test
public void testUnauthorizedXMLLangAttribute() {
String msg = extractInvalidFormatMessage("UnauthorizedXMLLangAttributeFAIL.docx");
assertEquals("OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.", msg);
@@ -213,6 +226,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.5 rule.
*/
+ @Test
public void testLimitedXSITypeAttribute_NotPresent() {
String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_NotPresentFAIL.docx");
assertEquals("The element 'created' must have the 'xsi:type' attribute present !", msg);
@@ -221,6 +235,7 @@ public final class TestOPCComplianceCore
/**
* Test M4.5 rule.
*/
+ @Test
public void testLimitedXSITypeAttribute_PresentWithUnauthorizedValue() {
String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF', but had 'W3CDTF' !", msg);
@@ -230,6 +245,7 @@ public final class TestOPCComplianceCore
* Document with no core properties - testing at the OPC level,
* saving into a new stream
*/
+ @Test
public void testNoCoreProperties_saveNew() throws Exception {
String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
@@ -277,6 +293,7 @@ public final class TestOPCComplianceCore
* 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";
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java?rev=1751891&r1=1751890&r2=1751891&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java Fri Jul 8 12:07:20 2016
@@ -17,9 +17,9 @@
package org.apache.poi.openxml4j.opc.compliance;
-import java.io.IOException;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -31,6 +31,7 @@ import org.apache.poi.openxml4j.opc.Pack
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.junit.Test;
/**
* Test Open Packaging Convention package model compliance.
@@ -40,13 +41,14 @@ import org.apache.poi.openxml4j.opc.Targ
*
* @author Julien Chable
*/
-public class TestOPCCompliancePackageModel extends TestCase {
+public class TestOPCCompliancePackageModel {
/**
* A package implementer shall neither create nor recognize a part with a
* part name derived from another part name by appending segments to it.
* [M1.11]
*/
+ @Test
public void testPartNameDerivationAdditionFailure() {
OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
try {
@@ -72,6 +74,7 @@ public class TestOPCCompliancePackageMod
* part name derived from another part name by appending segments to it.
* [M1.11]
*/
+ @Test
public void testPartNameDerivationReadingFailure() throws IOException {
String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
try {
@@ -89,6 +92,7 @@ public class TestOPCCompliancePackageMod
* implementers shall neither create nor recognize packages with equivalent
* part names.
*/
+ @Test
public void testAddPackageAlreadyAddFailure() throws Exception {
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName name1 = null;
@@ -113,6 +117,7 @@ public class TestOPCCompliancePackageMod
* implementers shall neither create nor recognize packages with equivalent
* part names.
*/
+ @Test
public void testAddPackageAlreadyAddFailure2() throws Exception {
OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
PackagePartName partName = null;
@@ -138,6 +143,7 @@ public class TestOPCCompliancePackageMod
* 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;
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java?rev=1751891&r1=1751890&r2=1751891&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java Fri Jul 8 12:07:20 2016
@@ -17,14 +17,17 @@
package org.apache.poi.openxml4j.opc.compliance;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.net.URI;
import java.net.URISyntaxException;
-import junit.framework.TestCase;
-
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.junit.Test;
/**
* Test part name Open Packaging Convention compliance.
@@ -77,13 +80,14 @@ import org.apache.poi.openxml4j.opc.Pack
*
* @author Julien Chable
*/
-public final class TestOPCCompliancePartName extends TestCase {
+public final class TestOPCCompliancePartName {
/**
* Test some common invalid names.
*
* A segment shall not contain percent-encoded unreserved characters. [M1.8]
*/
+ @Test
public void testInvalidPartNames() {
String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };
for (String s : invalidNames) {
@@ -102,6 +106,7 @@ public final class TestOPCCompliancePart
/**
* Test some common valid names.
*/
+ @Test
public void testValidPartNames() throws URISyntaxException {
String[] validNames = { "/xml/item1.xml", "/document.xml",
"/a/%D1%86.xml" };
@@ -113,6 +118,7 @@ public final class TestOPCCompliancePart
/**
* A part name shall not be empty. [M1.1]
*/
+ @Test
public void testEmptyPartNameFailure() throws URISyntaxException {
try {
PackagingURIHelper.createPartName(new URI(""));
@@ -129,6 +135,7 @@ public final class TestOPCCompliancePart
*
* A segment shall include at least one non-dot character. [M1.10]
*/
+ @Test
public void testPartNameWithInvalidSegmentsFailure() {
String[] invalidNames = { "//document.xml", "//word/document.xml",
"/word//document.rels", "/word//rels//document.rels",
@@ -148,6 +155,7 @@ public final class TestOPCCompliancePart
* A segment shall not hold any characters other than ipchar (RFC 3987) characters.
* [M1.6].
*/
+ @Test
public void testPartNameWithNonPCharCharacters() {
String[] validNames = { "/doc&.xml" };
try {
@@ -164,6 +172,7 @@ public final class TestOPCCompliancePart
/**
* A segment shall not contain percent-encoded unreserved characters [M1.8].
*/
+ @Test
public void testPartNameWithUnreservedEncodedCharactersFailure() {
String[] invalidNames = { "/a/docum%65nt.xml" };
try {
@@ -180,6 +189,7 @@ public final class TestOPCCompliancePart
/**
* A part name shall start with a forward slash ('/') character. [M1.4]
*/
+ @Test
public void testPartNameStartsWithAForwardSlashFailure()
throws URISyntaxException {
try {
@@ -193,6 +203,7 @@ public final class TestOPCCompliancePart
/**
* A part name shall not have a forward slash as the last character. [M1.5]
*/
+ @Test
public void testPartNameEndsWithAForwardSlashFailure()
throws URISyntaxException {
try {
@@ -207,6 +218,7 @@ public final class TestOPCCompliancePart
* Part name equivalence is determined by comparing part names as
* case-insensitive ASCII strings. [M1.12]
*/
+ @Test
public void testPartNameComparaison() throws Exception {
String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml", "/rels/.rels" };
@@ -225,6 +237,7 @@ public final class TestOPCCompliancePart
*
* 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" };
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org