@Test
public void importReferrerNodeBeforeReferencedNodeShouldNotLoseBackreference() throws Exception {
Node testRoot = session.getRootNode().addNode("testRoot");
Node referrerFirst = testRoot.addNode("referrerFirst");
Node referenceableNode = testRoot.addNode("referenceable");
referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
Node referrerTwo = testRoot.addNode("referrerTwo");
Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false);
referrerTwo.setProperty("prop1", strongRefValue);
referrerFirst.setProperty("prop1", strongRefValue);
session.save();
assertEquals(2, session.getNode("/testRoot/referenceable").getReferences().getSize());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
session.exportSystemView("/testRoot", outputStream, false, false);
session.getNode("/testRoot").remove();
session.save();
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
session.importXML("/", inputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.save();
assertEquals(2, session.getNode("/testRoot/referenceable").getReferences().getSize());
}