use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project poi by apache.
the class TestOPCComplianceCoreProperties method extractInvalidFormatMessage.
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");
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project poi by apache.
the class TestOPCCompliancePackageModel method testPartNameDerivationAdditionFailure.
/**
* 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 {
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]");
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project poi by apache.
the class TestOPCCompliancePackageModel method testAddPackageAlreadyAddFailure2.
/**
* Rule M1.12 : Packages shall not contain equivalent part names and package
* 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;
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]");
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project poi by apache.
the class TestOPCCompliancePackageModel method testAddRelationshipRelationshipsPartFailure.
/**
* 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.
*/
@Test
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");
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project poi by apache.
the class TestOPCCompliancePartName method testPartNameStartsWithAForwardSlashFailure.
/**
* A part name shall start with a forward slash ('/') character. [M1.4]
*/
@Test
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
}
}
Aggregations