@Test
@FixFor("MODE-2096")
public void shouldReorderTransientChildrenAtEnd() throws Exception {

    Node parent = session.getRootNode().addNode("parent", "nt:unstructured");
    try {
        parent.addNode("child1");
        parent.addNode("child2");
        parent.addNode("child3");
        parent.addNode("child4");
        parent.addNode("child5");
        parent.addNode("child6");
        parent.orderBefore("child5", "child4");
        parent.orderBefore("child6", "child4");
        parent.orderBefore("child3", "child2");
        parent.orderBefore("child1", null);
        parent.orderBefore("child2", null);
        session.save();
        List<String> paths = new ArrayList<String>();
        NodeIterator nodeIterator = parent.getNodes();
        while (nodeIterator.hasNext()) {
            paths.add(nodeIterator.nextNode().getPath());
        }
        assertEquals(6, paths.size());
        int child5Idx = paths.indexOf("/parent/child5");
        int child6Idx = paths.indexOf("/parent/child6");
        int child4Idx = paths.indexOf("/parent/child4");
        int child3Idx = paths.indexOf("/parent/child3");
        int child2Idx = paths.indexOf("/parent/child2");
        assertTrue("/parent/child5 not moved before /parent/child4", child5Idx < child4Idx);
        assertTrue("/parent/child6 not moved before /parent/child4", child6Idx < child4Idx);
        assertTrue("/parent/child3 not moved before /parent/child2", child3Idx < child2Idx);
        assertEquals(Arrays.asList("/parent/child1", "/parent/child2"), paths.subList(4, 6));
    } finally {
        parent.remove();
        session.save();
    }
}