diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-04-19 17:10:56 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-04-19 17:10:56 +0000 |
commit | d87ffbc1b06405c463b7896b7e8dafd97e2539fa (patch) | |
tree | 3ea1c25eefaa1dcc97e204ca7d8f71db2aad4a1b /poi-ooxml | |
parent | ee525b647727faaeafe0e1636bcd558c77e5c205 (diff) | |
download | poi-d87ffbc1b06405c463b7896b7e8dafd97e2539fa.tar.gz poi-d87ffbc1b06405c463b7896b7e8dafd97e2539fa.zip |
update tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917164 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
3 files changed, 23 insertions, 16 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java index 570f371258..32ef6eed8d 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java @@ -232,9 +232,14 @@ public class POIXMLDocumentPart { } /** - * Returns the list of child relations for this POIXMLDocumentPart + * Returns the list of child relations for this POIXMLDocumentPart. + * + * <p> + * Since POI 5.2.6, Reference Relationships are stored separately from other child relations. + * </p> * * @return child relations + * @see #getReferenceRelationships() for reference relationships (e.g. hyperlinks) */ public final List<RelationPart> getRelationParts() { List<RelationPart> l = new ArrayList<>(relations.values()); @@ -746,7 +751,7 @@ public class POIXMLDocumentPart { * @return true, if the relation was removed * @since POI 5.2.6 */ - public boolean removeReferenceRelationship(String relId) { + public final boolean removeReferenceRelationship(String relId) { ReferenceRelationship existing = referenceRelationships.remove(relId); if (existing != null) { packagePart.removeRelationship(relId); @@ -763,7 +768,7 @@ public class POIXMLDocumentPart { * @return the reference relationship or {@code null} if not found * @since POI 5.2.6 */ - public ReferenceRelationship getReferenceRelationship(String relId) { + public final ReferenceRelationship getReferenceRelationship(String relId) { return referenceRelationships.get(relId); } @@ -776,7 +781,7 @@ public class POIXMLDocumentPart { * @return the created reference relationship * @since POI 5.2.6 */ - public HyperlinkRelationship createHyperlink(URI uri, boolean isExternal, String relId) { + public final HyperlinkRelationship createHyperlink(URI uri, boolean isExternal, String relId) { PackageRelationship pr = packagePart.addRelationship(uri, isExternal ? TargetMode.EXTERNAL : TargetMode.INTERNAL, PackageRelationshipTypes.HYPERLINK_PART, relId); HyperlinkRelationship hyperlink = new HyperlinkRelationship(this, uri, isExternal, relId); @@ -789,8 +794,9 @@ public class POIXMLDocumentPart { * * @return reference relationships * @since POI 5.2.6 + * @see #getRelationParts() for child relations */ - public List<ReferenceRelationship> getReferenceRelationships() { + public final List<ReferenceRelationship> getReferenceRelationships() { List<ReferenceRelationship> list = new ArrayList<>(referenceRelationships.values()); return Collections.unmodifiableList(list); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java index 7bbbea564b..b00be391ac 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java @@ -326,10 +326,12 @@ class TestRelationships { assertNotNull(rId1); URI parent = drawingPart.getPartName().getURI(); // Hyperlink is not a target of relativize() because it is not resolved based on sourceURI in getTargetURI() -// URI rel1 = parent.relativize(rId1.getTargetURI()); -// URI rel11 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId1.getTargetURI()); -// assertEquals("'Another Sheet'!A1", rel1.getFragment()); -// assertEquals("'Another Sheet'!A1", rel11.getFragment()); + URI rel1 = parent.relativize(rId1.getTargetURI()); + assertEquals("'Another Sheet'!A1", rel1.getFragment()); + URI rel11 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId1.getTargetURI()); + // the following changed with https://github.com/apache/poi/pull/617 + //assertEquals("'Another Sheet'!A1", rel11.getFragment()); + assertNull(rel11.getFragment()); PackageRelationship rId2 = drawingPart.getRelationship("rId2"); URI rel2 = PackagingURIHelper.relativizeURI(drawingPart.getPartName().getURI(), rId2.getTargetURI()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java index bf6499d6ce..da7ae0f37a 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java @@ -17,13 +17,6 @@ package org.apache.poi.xssf; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.apache.poi.ooxml.ReferenceRelationship; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; @@ -47,6 +40,8 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPictureNo import java.io.IOException; +import static org.junit.jupiter.api.Assertions.*; + class TestXSSFCloneSheet extends BaseTestCloneSheet { public TestXSSFCloneSheet() { super(XSSFITestDataProvider.instance); @@ -208,6 +203,10 @@ class TestXSSFCloneSheet extends BaseTestCloneSheet { PackageRelationship imageRel2 = drawing2.getRelationPartById(imageRelId2).getRelationship(); assertEquals(imageRelationType, imageRel2.getRelationshipType()); assertEquals(imageTargetUrl, imageRel2.getTargetURI().toString()); + + assertTrue(drawing2.removeReferenceRelationship(linkRelId2)); + assertFalse(drawing2.removeReferenceRelationship(linkRelId2)); + assertNull(drawing2.getReferenceRelationship(linkRelId2)); } } } |