Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2375

Import referrer node before referenced node should not lose backreference

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 4.1.0.Final, 3.8.x-prod-ip6.3
    • 3.8.1.Final
    • JCR
    • None
    • Hide
      @Test
      public void importReferrerNodeBeforeReferencedNodeShouldNotLoseBackreference() throws Exception {
          // ARRANGE
          Node testRoot = session.getRootNode().addNode("testRoot");
      
          Node referrerFirst = testRoot.addNode("referrerFirst");
      
          // Create referenceable node
          Node referenceableNode = testRoot.addNode("referenceable");
          referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
      
          // Create second referrer
          Node referrerTwo = testRoot.addNode("referrerTwo");
          Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false);
          referrerTwo.setProperty("prop1", strongRefValue);
      
          // Set strong reference for the first referrer to referenceable node
          referrerFirst.setProperty("prop1", strongRefValue);
      
          session.save();
      
          // Check that we have two referrers
          assertEquals(2, session.getNode("/testRoot/referenceable").getReferences().getSize());
      
          // ACT
          // Export nodes will be in the following order: referrerFirst, referenceable, referrerTwo
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
          session.exportSystemView("/testRoot", outputStream, false, false);
      
          // Cleanup
          session.getNode("/testRoot").remove();
          session.save();
      
          // Import nodes.
          ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
          session.importXML("/", inputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
          session.save();
      
          // ASSERT
          // Check that we have two referrers.
          // We must not lose the referrer from node referrerFirst.
          assertEquals(2, session.getNode("/testRoot/referenceable").getReferences().getSize());
      }
      
      Show
      @Test public void importReferrerNodeBeforeReferencedNodeShouldNotLoseBackreference() throws Exception { // ARRANGE Node testRoot = session.getRootNode().addNode( "testRoot" ); Node referrerFirst = testRoot.addNode( "referrerFirst" ); // Create referenceable node Node referenceableNode = testRoot.addNode( "referenceable" ); referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString()); // Create second referrer Node referrerTwo = testRoot.addNode( "referrerTwo" ); Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false ); referrerTwo.setProperty( "prop1" , strongRefValue); // Set strong reference for the first referrer to referenceable node referrerFirst.setProperty( "prop1" , strongRefValue); session.save(); // Check that we have two referrers assertEquals(2, session.getNode( "/testRoot/referenceable" ).getReferences().getSize()); // ACT // Export nodes will be in the following order: referrerFirst, referenceable, referrerTwo ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); session.exportSystemView( "/testRoot" , outputStream, false , false ); // Cleanup session.getNode( "/testRoot" ).remove(); session.save(); // Import nodes. ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); session.importXML( "/" , inputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); session.save(); // ASSERT // Check that we have two referrers. // We must not lose the referrer from node referrerFirst. assertEquals(2, session.getNode( "/testRoot/referenceable" ).getReferences().getSize()); }

      We have referenceable node, referrerFirst node and referrerTwo node.
      referrerFirst and referrerTwo has references to referenceable node.After export and import this nodes, referenceable node lose referrerFirst.

              hchiorean Horia Chiorean (Inactive)
              gbelov_jira German Belov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: