mirror of https://github.com/apache/poi.git
whitespace and +svn:eol-style=native
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751867 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
79c5a9f021
commit
06e170fffc
|
@ -30,81 +30,81 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
|
|
||||||
public final class TestContentTypeManager extends TestCase {
|
public final class TestContentTypeManager extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the properties part content parsing.
|
* Test the properties part content parsing.
|
||||||
*/
|
*/
|
||||||
public void disabled_testContentType() throws Exception {
|
public void disabled_testContentType() throws Exception {
|
||||||
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
|
String filepath = OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
|
||||||
|
|
||||||
// Retrieves core properties part
|
// Retrieves core properties part
|
||||||
OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ);
|
OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ);
|
||||||
PackageRelationship corePropertiesRelationship = p
|
PackageRelationship corePropertiesRelationship = p
|
||||||
.getRelationshipsByType(
|
.getRelationshipsByType(
|
||||||
PackageRelationshipTypes.CORE_PROPERTIES)
|
PackageRelationshipTypes.CORE_PROPERTIES)
|
||||||
.getRelationship(0);
|
.getRelationship(0);
|
||||||
PackagePart coreDocument = p.getPart(corePropertiesRelationship);
|
PackagePart coreDocument = p.getPart(corePropertiesRelationship);
|
||||||
|
|
||||||
ContentTypeManager ctm = new ZipContentTypeManager(coreDocument.getInputStream(), p);
|
ContentTypeManager ctm = new ZipContentTypeManager(coreDocument.getInputStream(), p);
|
||||||
|
|
||||||
// TODO - finish writing this test
|
// TODO - finish writing this test
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the addition of several default and override content types.
|
* Test the addition of several default and override content types.
|
||||||
*/
|
*/
|
||||||
public void testContentTypeAddition() throws Exception {
|
public void testContentTypeAddition() throws Exception {
|
||||||
ContentTypeManager ctm = new ZipContentTypeManager(null, null);
|
ContentTypeManager ctm = new ZipContentTypeManager(null, null);
|
||||||
|
|
||||||
PackagePartName name1 = PackagingURIHelper.createPartName("/foo/foo.XML");
|
PackagePartName name1 = PackagingURIHelper.createPartName("/foo/foo.XML");
|
||||||
PackagePartName name2 = PackagingURIHelper.createPartName("/foo/foo2.xml");
|
PackagePartName name2 = PackagingURIHelper.createPartName("/foo/foo2.xml");
|
||||||
PackagePartName name3 = PackagingURIHelper.createPartName("/foo/doc.rels");
|
PackagePartName name3 = PackagingURIHelper.createPartName("/foo/doc.rels");
|
||||||
PackagePartName name4 = PackagingURIHelper.createPartName("/foo/doc.RELS");
|
PackagePartName name4 = PackagingURIHelper.createPartName("/foo/doc.RELS");
|
||||||
|
|
||||||
// Add content types
|
// Add content types
|
||||||
ctm.addContentType(name1, "foo-type1");
|
ctm.addContentType(name1, "foo-type1");
|
||||||
ctm.addContentType(name2, "foo-type2");
|
ctm.addContentType(name2, "foo-type2");
|
||||||
ctm.addContentType(name3, "text/xml+rel");
|
ctm.addContentType(name3, "text/xml+rel");
|
||||||
ctm.addContentType(name4, "text/xml+rel");
|
ctm.addContentType(name4, "text/xml+rel");
|
||||||
|
|
||||||
assertEquals(ctm.getContentType(name1), "foo-type1");
|
assertEquals(ctm.getContentType(name1), "foo-type1");
|
||||||
assertEquals(ctm.getContentType(name2), "foo-type2");
|
assertEquals(ctm.getContentType(name2), "foo-type2");
|
||||||
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
||||||
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the addition then removal of content types.
|
* Test the addition then removal of content types.
|
||||||
*/
|
*/
|
||||||
public void testContentTypeRemoval() throws Exception {
|
public void testContentTypeRemoval() throws Exception {
|
||||||
ContentTypeManager ctm = new ZipContentTypeManager(null, null);
|
ContentTypeManager ctm = new ZipContentTypeManager(null, null);
|
||||||
|
|
||||||
PackagePartName name1 = PackagingURIHelper.createPartName("/foo/foo.xml");
|
PackagePartName name1 = PackagingURIHelper.createPartName("/foo/foo.xml");
|
||||||
PackagePartName name2 = PackagingURIHelper.createPartName("/foo/foo2.xml");
|
PackagePartName name2 = PackagingURIHelper.createPartName("/foo/foo2.xml");
|
||||||
PackagePartName name3 = PackagingURIHelper.createPartName("/foo/doc.rels");
|
PackagePartName name3 = PackagingURIHelper.createPartName("/foo/doc.rels");
|
||||||
PackagePartName name4 = PackagingURIHelper.createPartName("/foo/doc.RELS");
|
PackagePartName name4 = PackagingURIHelper.createPartName("/foo/doc.RELS");
|
||||||
|
|
||||||
// Add content types
|
// Add content types
|
||||||
ctm.addContentType(name1, "foo-type1");
|
ctm.addContentType(name1, "foo-type1");
|
||||||
ctm.addContentType(name2, "foo-type2");
|
ctm.addContentType(name2, "foo-type2");
|
||||||
ctm.addContentType(name3, "text/xml+rel");
|
ctm.addContentType(name3, "text/xml+rel");
|
||||||
ctm.addContentType(name4, "text/xml+rel");
|
ctm.addContentType(name4, "text/xml+rel");
|
||||||
ctm.removeContentType(name2);
|
ctm.removeContentType(name2);
|
||||||
ctm.removeContentType(name3);
|
ctm.removeContentType(name3);
|
||||||
|
|
||||||
assertEquals(ctm.getContentType(name1), "foo-type1");
|
assertEquals(ctm.getContentType(name1), "foo-type1");
|
||||||
assertEquals(ctm.getContentType(name2), "foo-type1");
|
assertEquals(ctm.getContentType(name2), "foo-type1");
|
||||||
assertEquals(ctm.getContentType(name3), null);
|
assertEquals(ctm.getContentType(name3), null);
|
||||||
|
|
||||||
ctm.removeContentType(name1);
|
ctm.removeContentType(name1);
|
||||||
assertEquals(ctm.getContentType(name1), null);
|
assertEquals(ctm.getContentType(name1), null);
|
||||||
assertEquals(ctm.getContentType(name2), null);
|
assertEquals(ctm.getContentType(name2), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the addition then removal of content types in a package.
|
* Test the addition then removal of content types in a package.
|
||||||
*/
|
*/
|
||||||
public void testContentTypeRemovalPackage() {
|
public void testContentTypeRemovalPackage() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue