in src/main/java/org/apache/sling/launchpad/webapp/integrationtest/resourceresolver/ResourceResolverGeneralTest.java [2434:2505]
public void test_resolve_with_sling_vanity_path_order() throws Exception {
final String vanityPath = "/ordering";
// create two nodes - child2 with a higher order
Node child1 = rootNode.addNode("child1");
child1.addMixin("sling:VanityPath");
child1.setProperty("sling:vanityPath", vanityPath);
child1.setProperty("sling:vanityOrder", 100);
Node child2 = rootNode.addNode("child2");
child2.addMixin("sling:VanityPath");
child2.setProperty("sling:vanityPath", vanityPath);
child2.setProperty("sling:vanityOrder", 200);
try {
saveMappings(session);
// we should get child2 now
Resource rsrc = resResolver.resolve(vanityPath);
assertNotNull(rsrc);
assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
// remove 2
child2.remove();
saveMappings(session);
// we should get child 1 now
rsrc = resResolver.resolve(vanityPath);
assertNotNull(rsrc);
assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
assertEquals("Path does not match", child1.getPath(), rsrc.getPath());
// readding child2
child2 = rootNode.addNode("child2");
child2.addMixin("sling:VanityPath");
child2.setProperty("sling:vanityPath", vanityPath);
child2.setProperty("sling:vanityOrder", 200);
saveMappings(session);
// we should get child2 now
rsrc = resResolver.resolve(vanityPath);
assertNotNull(rsrc);
assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
// change order of child 1 to make it higher than child 2
child1.setProperty("sling:vanityOrder", 300);
saveMappings(session);
// we should get child 1 now
rsrc = resResolver.resolve(vanityPath);
assertNotNull(rsrc);
assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
assertEquals("Path does not match", child1.getPath(), rsrc.getPath());
// change order of child 1 to make it lower than child 2
child1.setProperty("sling:vanityOrder", 50);
saveMappings(session);
// we should get child 2 now
rsrc = resResolver.resolve(vanityPath);
assertNotNull(rsrc);
assertFalse("Resource should exist", ResourceUtil.isNonExistingResource(rsrc));
assertEquals("Path does not match", child2.getPath(), rsrc.getPath());
} finally {
child1.remove();
if (rootNode.hasNode("child2")) {
rootNode.getNode("child2").remove();
}
session.save();
}
}