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 11:55:21 UTC

svn commit: r1751890 - in /poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance: TestOPCComplianceCoreProperties.java TestOPCCompliancePackageModel.java TestOPCCompliancePartName.java

Author: onealj
Date: Fri Jul  8 11:55:21 2016
New Revision: 1751890

URL: http://svn.apache.org/viewvc?rev=1751890&view=rev
Log:
whitespace and +svn:eol-style=native

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java   (contents, props changed)
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java   (contents, props changed)
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java   (contents, props changed)

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=1751890&r1=1751889&r2=1751890&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 11:55:21 2016
@@ -75,47 +75,47 @@ import junit.framework.TestCase;
  */
 public final class TestOPCComplianceCoreProperties extends TestCase {
 
-	public void testCorePropertiesPart() {
-		OPCPackage pkg;
-		try {
-			InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
-			pkg = OPCPackage.open(is);
-		} catch (InvalidFormatException e) {
-			throw new RuntimeException(e);
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-		pkg.revert();
-	}
-
-	private static String extractInvalidFormatMessage(String sampleNameSuffix) {
-		InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
-		OPCPackage pkg;
-		try {
-			pkg = OPCPackage.open(is);
-		} catch (InvalidFormatException e) {
-			// no longer required for successful test
-			return e.getMessage();
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-		pkg.revert();
-		throw new AssertionFailedError("expected OPC compliance exception was not thrown");
-	}
-	
-	/**
-	 * Test M4.1 rule.
-	 */
-	public void testOnlyOneCorePropertiesPart() throws Exception {
-	   // We have relaxed this check, so we can read the file anyway
-	   try {
-	      extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");
-	      fail("M4.1 should be being relaxed");
-	   } catch (AssertionFailedError e) {
-		   // expected here
-	   }
-	   
-	   // We will use the first core properties, and ignore the others
+    public void testCorePropertiesPart() {
+        OPCPackage pkg;
+        try {
+            InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
+            pkg = OPCPackage.open(is);
+        } catch (InvalidFormatException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        pkg.revert();
+    }
+
+    private static String extractInvalidFormatMessage(String sampleNameSuffix) {
+        InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
+        OPCPackage pkg;
+        try {
+            pkg = OPCPackage.open(is);
+        } catch (InvalidFormatException e) {
+            // no longer required for successful test
+            return e.getMessage();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        pkg.revert();
+        throw new AssertionFailedError("expected OPC compliance exception was not thrown");
+    }
+    
+    /**
+     * Test M4.1 rule.
+     */
+    public void testOnlyOneCorePropertiesPart() throws Exception {
+       // We have relaxed this check, so we can read the file anyway
+       try {
+          extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx");
+          fail("M4.1 should be being relaxed");
+       } catch (AssertionFailedError e) {
+           // expected here
+       }
+       
+       // We will use the first core properties, and ignore the others
       InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx");
       OPCPackage pkg = OPCPackage.open(is);
       
@@ -128,104 +128,104 @@ public final class TestOPCComplianceCore
             "/docProps/core.xml",
             pkg.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).get(0).getPartName().toString()
       );
-	}
-	
-	private static URI createURI(String text) {
-		try {
-			return new URI(text);
-		} catch (URISyntaxException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	/**
-	 * Test M4.1 rule.
-	 */
-	public void testOnlyOneCorePropertiesPart_AddRelationship() {
-		InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
-		OPCPackage pkg;
-		try {
-			pkg = OPCPackage.open(is);
-		} catch (InvalidFormatException e) {
-			throw new RuntimeException(e);
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-		URI partUri = createURI("/docProps/core2.xml");
-		try {
-			pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
-					PackageRelationshipTypes.CORE_PROPERTIES);
-			// no longer fail on compliance error
-			//fail("expected OPC compliance exception was not thrown");
-		} catch (InvalidFormatException e) {
-			throw new RuntimeException(e);
-		} catch (InvalidOperationException e) {
-			// expected during successful test
-			assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
-		}
-		pkg.revert();
-	}
-
-	/**
-	 * Test M4.1 rule.
-	 */
-	public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
-		String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
-		OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
-
-		URI partUri = createURI("/docProps/core2.xml");
-		try {
-			pkg.createPart(PackagingURIHelper.createPartName(partUri),
-					ContentTypes.CORE_PROPERTIES_PART);
-			// no longer fail on compliance error
-			//fail("expected OPC compliance exception was not thrown");
-		} catch (InvalidOperationException e) {
-			// expected during successful test
-			assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
-		}
-		pkg.revert();
-	}
-
-	/**
-	 * Test M4.2 rule.
-	 */
-	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.
-	 */
-	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.
-	 */
-	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.
-	 */
-	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.
-	 */
-	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);
-	}
-	
+    }
+    
+    private static URI createURI(String text) {
+        try {
+            return new URI(text);
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Test M4.1 rule.
+     */
+    public void testOnlyOneCorePropertiesPart_AddRelationship() {
+        InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
+        OPCPackage pkg;
+        try {
+            pkg = OPCPackage.open(is);
+        } catch (InvalidFormatException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        URI partUri = createURI("/docProps/core2.xml");
+        try {
+            pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
+                    PackageRelationshipTypes.CORE_PROPERTIES);
+            // no longer fail on compliance error
+            //fail("expected OPC compliance exception was not thrown");
+        } catch (InvalidFormatException e) {
+            throw new RuntimeException(e);
+        } catch (InvalidOperationException e) {
+            // expected during successful test
+            assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
+        }
+        pkg.revert();
+    }
+
+    /**
+     * Test M4.1 rule.
+     */
+    public void testOnlyOneCorePropertiesPart_AddPart() throws InvalidFormatException {
+        String sampleFileName = "OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx";
+        OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
+
+        URI partUri = createURI("/docProps/core2.xml");
+        try {
+            pkg.createPart(PackagingURIHelper.createPartName(partUri),
+                    ContentTypes.CORE_PROPERTIES_PART);
+            // no longer fail on compliance error
+            //fail("expected OPC compliance exception was not thrown");
+        } catch (InvalidOperationException e) {
+            // expected during successful test
+            assertEquals("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !", e.getMessage());
+        }
+        pkg.revert();
+    }
+
+    /**
+     * Test M4.2 rule.
+     */
+    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.
+     */
+    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.
+     */
+    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.
+     */
+    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.
+     */
+    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

Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1751890&r1=1751889&r2=1751890&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 11:55:21 2016
@@ -42,118 +42,118 @@ import org.apache.poi.openxml4j.opc.Targ
  */
 public class TestOPCCompliancePackageModel extends TestCase {
 
-	/**
-	 * 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]
-	 */
-	public void testPartNameDerivationAdditionFailure() {
-		OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
-		try {
-			PackagePartName name = PackagingURIHelper
-					.createPartName("/word/document.xml");
-			PackagePartName nameDerived = PackagingURIHelper
-					.createPartName("/word/document.xml/image1.gif");
-			pkg.createPart(name, ContentTypes.XML);
-			pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
-		} catch (InvalidOperationException e) {
-			pkg.revert();
-			return;
-		} catch (InvalidFormatException e) {
-			fail(e.getMessage());
-		}
-		fail("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]");
-	}
-
-	/**
-	 * 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]
-	 */
-	public void testPartNameDerivationReadingFailure() throws IOException {
-		String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
-		try {
-			OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
-		} catch (InvalidFormatException e) {
-			return;
-		}
-		fail("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]");
-	}
-
-	/**
-	 * Rule M1.12 : Packages shall not contain equivalent part names and package
-	 * implementers shall neither create nor recognize packages with equivalent
-	 * part names.
-	 */
-	public void testAddPackageAlreadyAddFailure() throws Exception {
-		OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-		PackagePartName name1 = null;
-		PackagePartName name2 = null;
-		try {
-			name1 = PackagingURIHelper.createPartName("/word/document.xml");
-			name2 = PackagingURIHelper.createPartName("/word/document.xml");
-		} catch (InvalidFormatException e) {
-			throw new Exception(e.getMessage());
-		}
-		pkg.createPart(name1, ContentTypes.XML);
-		try {
-			pkg.createPart(name2, ContentTypes.XML);
-		} catch (PartAlreadyExistsException e) {
-			return;
-		}
-		fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
-	}
-
-	/**
-	 * Rule M1.12 : Packages shall not contain equivalent part names and package
-	 * implementers shall neither create nor recognize packages with equivalent
-	 * part names.
-	 */
-	public void testAddPackageAlreadyAddFailure2() throws Exception {
-		OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-		PackagePartName partName = null;
-		try {
-			partName = PackagingURIHelper.createPartName("/word/document.xml");
-		} catch (InvalidFormatException e) {
-			throw new Exception(e.getMessage());
-		}
-		pkg.createPart(partName, ContentTypes.XML);
-		try {
-			pkg.createPart(partName, ContentTypes.XML);
-		} catch (InvalidOperationException e) {
-			return;
-		}
-		fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
-	}
-
-	/**
-	 * Try to add a relationship to a relationship part.
-	 *
-	 * Check rule M1.25: The Relationships part shall not have relationships to
-	 * any other part. Package implementers shall enforce this requirement upon
-	 * the attempt to create such a relationship and shall treat any such
-	 * relationship as invalid.
-	 */
-	public void testAddRelationshipRelationshipsPartFailure() {
-		OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
-		PackagePartName name1 = null;
-		try {
-			name1 = PackagingURIHelper
-					.createPartName("/test/_rels/document.xml.rels");
-		} catch (InvalidFormatException e) {
-			fail("This exception should never happen !");
-		}
-
-		try {
-			pkg.addRelationship(name1, TargetMode.INTERNAL,
-					PackageRelationshipTypes.CORE_DOCUMENT);
-		} catch (InvalidOperationException e) {
-			return;
-		}
-		fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
-	}
+    /**
+     * 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]
+     */
+    public void testPartNameDerivationAdditionFailure() {
+        OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
+        try {
+            PackagePartName name = PackagingURIHelper
+                    .createPartName("/word/document.xml");
+            PackagePartName nameDerived = PackagingURIHelper
+                    .createPartName("/word/document.xml/image1.gif");
+            pkg.createPart(name, ContentTypes.XML);
+            pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
+        } catch (InvalidOperationException e) {
+            pkg.revert();
+            return;
+        } catch (InvalidFormatException e) {
+            fail(e.getMessage());
+        }
+        fail("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]");
+    }
+
+    /**
+     * 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]
+     */
+    public void testPartNameDerivationReadingFailure() throws IOException {
+        String filename = "OPCCompliance_DerivedPartNameFAIL.docx";
+        try {
+            OPCPackage.open(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename));
+        } catch (InvalidFormatException e) {
+            return;
+        }
+        fail("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]");
+    }
+
+    /**
+     * Rule M1.12 : Packages shall not contain equivalent part names and package
+     * implementers shall neither create nor recognize packages with equivalent
+     * part names.
+     */
+    public void testAddPackageAlreadyAddFailure() throws Exception {
+        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+        PackagePartName name1 = null;
+        PackagePartName name2 = null;
+        try {
+            name1 = PackagingURIHelper.createPartName("/word/document.xml");
+            name2 = PackagingURIHelper.createPartName("/word/document.xml");
+        } catch (InvalidFormatException e) {
+            throw new Exception(e.getMessage());
+        }
+        pkg.createPart(name1, ContentTypes.XML);
+        try {
+            pkg.createPart(name2, ContentTypes.XML);
+        } catch (PartAlreadyExistsException e) {
+            return;
+        }
+        fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
+    }
+
+    /**
+     * Rule M1.12 : Packages shall not contain equivalent part names and package
+     * implementers shall neither create nor recognize packages with equivalent
+     * part names.
+     */
+    public void testAddPackageAlreadyAddFailure2() throws Exception {
+        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+        PackagePartName partName = null;
+        try {
+            partName = PackagingURIHelper.createPartName("/word/document.xml");
+        } catch (InvalidFormatException e) {
+            throw new Exception(e.getMessage());
+        }
+        pkg.createPart(partName, ContentTypes.XML);
+        try {
+            pkg.createPart(partName, ContentTypes.XML);
+        } catch (InvalidOperationException e) {
+            return;
+        }
+        fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
+    }
+
+    /**
+     * Try to add a relationship to a relationship part.
+     *
+     * Check rule M1.25: The Relationships part shall not have relationships to
+     * any other part. Package implementers shall enforce this requirement upon
+     * the attempt to create such a relationship and shall treat any such
+     * relationship as invalid.
+     */
+    public void testAddRelationshipRelationshipsPartFailure() {
+        OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
+        PackagePartName name1 = null;
+        try {
+            name1 = PackagingURIHelper
+                    .createPartName("/test/_rels/document.xml.rels");
+        } catch (InvalidFormatException e) {
+            fail("This exception should never happen !");
+        }
+
+        try {
+            pkg.addRelationship(name1, TargetMode.INTERNAL,
+                    PackageRelationshipTypes.CORE_DOCUMENT);
+        } catch (InvalidOperationException e) {
+            return;
+        }
+        fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
+    }
 }

Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePackageModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1751890&r1=1751889&r2=1751890&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 11:55:21 2016
@@ -79,161 +79,161 @@ import org.apache.poi.openxml4j.opc.Pack
  */
 public final class TestOPCCompliancePartName extends TestCase {
 
-	/**
-	 * Test some common invalid names.
-	 *
-	 * A segment shall not contain percent-encoded unreserved characters. [M1.8]
-	 */
-	public void testInvalidPartNames() {
-		String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };
-		for (String s : invalidNames) {
-			URI uri = null;
-			try {
-				uri = new URI(s);
-			} catch (URISyntaxException e) {
-				assertTrue(s.equals("[Content_Types].xml"));
-				continue;
-			}
-			assertFalse("This part name SHOULD NOT be valid: " + s,
-					PackagingURIHelper.isValidPartName(uri));
-		}
-	}
-
-	/**
-	 * Test some common valid names.
-	 */
-	public void testValidPartNames() throws URISyntaxException {
-		String[] validNames = { "/xml/item1.xml", "/document.xml",
-				"/a/%D1%86.xml" };
-		for (String s : validNames)
-			assertTrue("This part name SHOULD be valid: " + s,
-					PackagingURIHelper.isValidPartName(new URI(s)));
-	}
-
-	/**
-	 * A part name shall not be empty. [M1.1]
-	 */
-	public void testEmptyPartNameFailure() throws URISyntaxException {
-		try {
-			PackagingURIHelper.createPartName(new URI(""));
-			fail("A part name shall not be empty. [M1.1]");
-		} catch (InvalidFormatException e) {
-			// Normal behaviour
-		}
-	}
-
-	/**
-	 * A part name shall not have empty segments. [M1.3]
-	 *
-	 * A segment shall not end with a dot ('.') character. [M1.9]
-	 *
-	 * A segment shall include at least one non-dot character. [M1.10]
-	 */
-	public void testPartNameWithInvalidSegmentsFailure() {
-		String[] invalidNames = { "//document.xml", "//word/document.xml",
-				"/word//document.rels", "/word//rels//document.rels",
-				"/xml./doc.xml", "/document.", "/./document.xml",
-				"/word/./doc.rels", "/%2F/document.xml" };
-		try {
-			for (String s : invalidNames)
-				assertFalse(
-						"A part name shall not have empty segments. [M1.3]",
-						PackagingURIHelper.isValidPartName(new URI(s)));
-		} catch (URISyntaxException e) {
-			fail();
-		}
-	}
-
-	/**
-	 * A segment shall not hold any characters other than ipchar (RFC 3987) characters.
-	 * [M1.6].
-	 */
-	public void testPartNameWithNonPCharCharacters() {
-		String[] validNames = { "/doc&.xml" };
-		try {
-			for (String s : validNames)
-				assertTrue(
-						"A segment shall not contain non pchar characters [M1.6] : "
-								+ s, PackagingURIHelper
-								.isValidPartName(new URI(s)));
-		} catch (URISyntaxException e) {
-			fail();
-		}
-	}
-
-	/**
-	 * A segment shall not contain percent-encoded unreserved characters [M1.8].
-	 */
-	public void testPartNameWithUnreservedEncodedCharactersFailure() {
-		String[] invalidNames = { "/a/docum%65nt.xml" };
-		try {
-			for (String s : invalidNames)
-				assertFalse(
-						"A segment shall not contain percent-encoded unreserved characters [M1.8] : "
-								+ s, PackagingURIHelper
-								.isValidPartName(new URI(s)));
-		} catch (URISyntaxException e) {
-			fail();
-		}
-	}
-
-	/**
-	 * A part name shall start with a forward slash ('/') character. [M1.4]
-	 */
-	public void testPartNameStartsWithAForwardSlashFailure()
-			throws URISyntaxException {
-		try {
-			PackagingURIHelper.createPartName(new URI("document.xml"));
-			fail("A part name shall start with a forward slash ('/') character. [M1.4]");
-		} catch (InvalidFormatException e) {
-			// Normal behaviour
-		}
-	}
-
-	/**
-	 * A part name shall not have a forward slash as the last character. [M1.5]
-	 */
-	public void testPartNameEndsWithAForwardSlashFailure()
-			throws URISyntaxException {
-		try {
-			PackagingURIHelper.createPartName(new URI("/document.xml/"));
-			fail("A part name shall not have a forward slash as the last character. [M1.5]");
-		} catch (InvalidFormatException e) {
-			// Normal behaviour
-		}
-	}
-
-	/**
-	 * Part name equivalence is determined by comparing part names as
-	 * case-insensitive ASCII strings. [M1.12]
-	 */
-	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" };
-		for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
-			PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
-			PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
-			assertTrue(p1.equals(p2));
-			assertTrue(p1.compareTo(p2) == 0);
-			assertTrue(p1.hashCode() == p2.hashCode());
-		}
-	}
-
-	/**
-	 * Part name equivalence is determined by comparing part names as
-	 * case-insensitive ASCII strings. [M1.12].
-	 *
-	 * All the comparisons MUST FAIL !
-	 */
-	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" };
-		for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
-			PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
-			PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
-			assertFalse(p1.equals(p2));
-			assertFalse(p1.compareTo(p2) == 0);
-			assertFalse(p1.hashCode() == p2.hashCode());
-		}
-	}
+    /**
+     * Test some common invalid names.
+     *
+     * A segment shall not contain percent-encoded unreserved characters. [M1.8]
+     */
+    public void testInvalidPartNames() {
+        String[] invalidNames = { "/", "/xml./doc.xml", "[Content_Types].xml", "//xml/." };
+        for (String s : invalidNames) {
+            URI uri = null;
+            try {
+                uri = new URI(s);
+            } catch (URISyntaxException e) {
+                assertTrue(s.equals("[Content_Types].xml"));
+                continue;
+            }
+            assertFalse("This part name SHOULD NOT be valid: " + s,
+                    PackagingURIHelper.isValidPartName(uri));
+        }
+    }
+
+    /**
+     * Test some common valid names.
+     */
+    public void testValidPartNames() throws URISyntaxException {
+        String[] validNames = { "/xml/item1.xml", "/document.xml",
+                "/a/%D1%86.xml" };
+        for (String s : validNames)
+            assertTrue("This part name SHOULD be valid: " + s,
+                    PackagingURIHelper.isValidPartName(new URI(s)));
+    }
+
+    /**
+     * A part name shall not be empty. [M1.1]
+     */
+    public void testEmptyPartNameFailure() throws URISyntaxException {
+        try {
+            PackagingURIHelper.createPartName(new URI(""));
+            fail("A part name shall not be empty. [M1.1]");
+        } catch (InvalidFormatException e) {
+            // Normal behaviour
+        }
+    }
+
+    /**
+     * A part name shall not have empty segments. [M1.3]
+     *
+     * A segment shall not end with a dot ('.') character. [M1.9]
+     *
+     * A segment shall include at least one non-dot character. [M1.10]
+     */
+    public void testPartNameWithInvalidSegmentsFailure() {
+        String[] invalidNames = { "//document.xml", "//word/document.xml",
+                "/word//document.rels", "/word//rels//document.rels",
+                "/xml./doc.xml", "/document.", "/./document.xml",
+                "/word/./doc.rels", "/%2F/document.xml" };
+        try {
+            for (String s : invalidNames)
+                assertFalse(
+                        "A part name shall not have empty segments. [M1.3]",
+                        PackagingURIHelper.isValidPartName(new URI(s)));
+        } catch (URISyntaxException e) {
+            fail();
+        }
+    }
+
+    /**
+     * A segment shall not hold any characters other than ipchar (RFC 3987) characters.
+     * [M1.6].
+     */
+    public void testPartNameWithNonPCharCharacters() {
+        String[] validNames = { "/doc&.xml" };
+        try {
+            for (String s : validNames)
+                assertTrue(
+                        "A segment shall not contain non pchar characters [M1.6] : "
+                                + s, PackagingURIHelper
+                                .isValidPartName(new URI(s)));
+        } catch (URISyntaxException e) {
+            fail();
+        }
+    }
+
+    /**
+     * A segment shall not contain percent-encoded unreserved characters [M1.8].
+     */
+    public void testPartNameWithUnreservedEncodedCharactersFailure() {
+        String[] invalidNames = { "/a/docum%65nt.xml" };
+        try {
+            for (String s : invalidNames)
+                assertFalse(
+                        "A segment shall not contain percent-encoded unreserved characters [M1.8] : "
+                                + s, PackagingURIHelper
+                                .isValidPartName(new URI(s)));
+        } catch (URISyntaxException e) {
+            fail();
+        }
+    }
+
+    /**
+     * A part name shall start with a forward slash ('/') character. [M1.4]
+     */
+    public void testPartNameStartsWithAForwardSlashFailure()
+            throws URISyntaxException {
+        try {
+            PackagingURIHelper.createPartName(new URI("document.xml"));
+            fail("A part name shall start with a forward slash ('/') character. [M1.4]");
+        } catch (InvalidFormatException e) {
+            // Normal behaviour
+        }
+    }
+
+    /**
+     * A part name shall not have a forward slash as the last character. [M1.5]
+     */
+    public void testPartNameEndsWithAForwardSlashFailure()
+            throws URISyntaxException {
+        try {
+            PackagingURIHelper.createPartName(new URI("/document.xml/"));
+            fail("A part name shall not have a forward slash as the last character. [M1.5]");
+        } catch (InvalidFormatException e) {
+            // Normal behaviour
+        }
+    }
+
+    /**
+     * Part name equivalence is determined by comparing part names as
+     * case-insensitive ASCII strings. [M1.12]
+     */
+    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" };
+        for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
+            PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
+            PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
+            assertTrue(p1.equals(p2));
+            assertTrue(p1.compareTo(p2) == 0);
+            assertTrue(p1.hashCode() == p2.hashCode());
+        }
+    }
+
+    /**
+     * Part name equivalence is determined by comparing part names as
+     * case-insensitive ASCII strings. [M1.12].
+     *
+     * All the comparisons MUST FAIL !
+     */
+    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" };
+        for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
+            PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
+            PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
+            assertFalse(p1.equals(p2));
+            assertFalse(p1.compareTo(p2) == 0);
+            assertFalse(p1.hashCode() == p2.hashCode());
+        }
+    }
 }

Propchange: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCCompliancePartName.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org