@Test
public void shouldRetrieveReferenceProperties() throws Exception {

    Node referenceableNode = session.getRootNode().addNode("referenceable");
    referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
    Node node1 = session.getRootNode().addNode("node1");
    Property prop1 = node1.setProperty("prop1", session.getValueFactory().createValue(referenceableNode, false));
    Property prop2 = node1.setProperty("prop2", session.getValueFactory().createValue(referenceableNode, true));
    Node node2 = session.getRootNode().addNode("node2");
    Property prop3 = node2.setProperty("prop3", session.getValueFactory().createValue(referenceableNode, false));
    Property prop4 = node2.setProperty("prop4", session.getValueFactory().createValue(referenceableNode, true));
    session.save();
    try {
        // check all strong references
        PropertyIterator propertyIterator = referenceableNode.getReferences();
        assertEquals(2, propertyIterator.getSize());
        Set<String> propertyNames = new HashSet<String>(2);
        while (propertyIterator.hasNext()) {
            propertyNames.add(propertyIterator.nextProperty().getName());
        }
        assertTrue(propertyNames.contains(prop1.getName()) && propertyNames.contains(prop3.getName()));
        propertyIterator = referenceableNode.getReferences("prop1");
        assertEquals(1, propertyIterator.getSize());
        assertEquals(prop1.getName(), propertyIterator.nextProperty().getName());
        propertyIterator = referenceableNode.getReferences("unknown");
        assertEquals(0, propertyIterator.getSize());
        // check all weak references
        propertyIterator = referenceableNode.getWeakReferences();
        assertEquals(2, propertyIterator.getSize());
        propertyNames = new HashSet<String>(2);
        while (propertyIterator.hasNext()) {
            propertyNames.add(propertyIterator.nextProperty().getName());
        }
        assertTrue(propertyNames.contains(prop2.getName()) && propertyNames.contains(prop4.getName()));
        propertyIterator = referenceableNode.getWeakReferences("prop4");
        assertEquals(1, propertyIterator.getSize());
        assertEquals(prop4.getName(), propertyIterator.nextProperty().getName());
        propertyIterator = referenceableNode.getWeakReferences("unknown");
        assertEquals(0, propertyIterator.getSize());
    } finally {
        node1.remove();
        node2.remove();
        referenceableNode.remove();
        session.save();
    }
}