]> source.dussan.org Git - poi.git/commitdiff
update tests
authorPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 17:10:56 +0000 (17:10 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 19 Apr 2024 17:10:56 +0000 (17:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917164 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestRelationships.java
poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java

index 570f371258e96c99783f899e564422034cb06ae0..32ef6eed8d1a4eb6a6df77100425949894d0fa8c 100644 (file)
@@ -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);
     }
index 7bbbea564b8f92c52afb5403b541ed428e71e40f..b00be391acf155554fc488f764aa20e5bfdd88e0 100644 (file)
@@ -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());
index bf6499d6cea5bb82efbb40555beee84443c309a6..da7ae0f37a74ceb6989ded3d6312f21a00b1b2d7 100644 (file)
 
 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));
         }
     }
 }