use of org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider in project sling by apache.
the class SightlyNatureTesterTest method testOnProject.
private void testOnProject(boolean hasSightlyNature) throws CoreException {
if (hasSightlyNature) {
projectAdapter.installFacet("sightly", "1.1");
}
final IPath sightlyTemplatePath = Path.fromPortableString("/jcr_root/libs/my/component/html.html");
projectAdapter.createOrUpdateFile(sightlyTemplatePath, new ByteArrayInputStream(("<html />").getBytes()));
// test on resources directly
assertEquals("Test on project", hasSightlyNature, tester.test(projectRule.getProject(), "sightlyNature", new Object[0], null));
assertEquals("Test on folder", hasSightlyNature, tester.test(projectRule.getProject().getFolder("jcr_root"), "sightlyNature", new Object[0], null));
assertEquals("Test on file", hasSightlyNature, tester.test(projectRule.getProject().getFile(sightlyTemplatePath), "sightlyNature", new Object[0], null));
// directly create the root node
SyncDir syncDirNode = new SyncDir((IFolder) projectRule.getProject().findMember("jcr_root"));
assertEquals("Test on sync dir node", hasSightlyNature, tester.test(syncDirNode, "sightlyNature", new Object[0], null));
// test on jcr nodes
JcrContentContentProvider contentProvider = new JcrContentContentProvider();
JcrNode firstChild = (JcrNode) contentProvider.getChildren(syncDirNode)[0];
assertEquals("Test on jcr node", hasSightlyNature, tester.test(firstChild, "sightlyNature", new Object[0], null));
}
use of org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider in project sling by apache.
the class JcrContentContentProviderTest method listChildrenOnSyncDirIgnoresWebInfAndMetaInf.
@Test
public void listChildrenOnSyncDirIgnoresWebInfAndMetaInf() throws Exception {
project.ensureDirectoryExists(Path.fromPortableString("jcr_root/WEB-INF"));
project.ensureDirectoryExists(Path.fromPortableString("jcr_root/META-INF"));
project.ensureDirectoryExists(Path.fromPortableString("jcr_root/content"));
// directly create the root node
SyncDir syncDirNode = new SyncDir((IFolder) contentProject.findMember("jcr_root"));
// assertion
Object[] children = new JcrContentContentProvider().getChildren(syncDirNode);
assertThat(children.length, equalTo(1));
JcrNode child = (JcrNode) children[0];
assertThat(child.getName(), equalTo("content"));
}
use of org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider in project sling by apache.
the class JcrContentContentProviderTest method assertIsNavigableAndHasNoChildren.
/**
* Asserts that the specified <tt>nodePath</tt> is reachable from the <tt>startNode</tt>
*
* <p>It further asserts that there are no children beyond the <tt>nodePath</tt>, i.e. it
* is and endpoint</p>
*
* @param startNode the node to start from
* @param nodePath the path that is reachable and an endpoint
*/
private void assertIsNavigableAndHasNoChildren(SyncDir startNode, String nodePath) {
JcrContentContentProvider contentProvider = new JcrContentContentProvider();
if (nodePath.charAt(0) == '/') {
nodePath = nodePath.substring(1);
}
String[] pathElements = nodePath.split("/");
JcrNode current = startNode;
segments: for (int i = 0; i < pathElements.length; i++) {
String expectedChildName = pathElements[i];
Object[] children = contentProvider.getChildren(current);
for (Object child : children) {
JcrNode childNode = (JcrNode) child;
// childNode.getName() does not seem to be usable here, so relying on the path
String childName = PathUtil.getName(childNode.getJcrPath());
if (childName.equals(expectedChildName)) {
current = childNode;
continue segments;
}
}
fail("Unable to navigate to '" + nodePath + "'. " + " No child named '" + expectedChildName + "'found for node at " + current.getJcrPath() + ", children: " + Arrays.toString(children));
}
Object[] children = contentProvider.getChildren(current);
if (children.length != 0) {
fail("Unexpected children for node at '" + current.getJcrPath() + "' : " + Arrays.toString(children));
}
}
Aggregations