Search in sources :

Example 6 with TreeElement

use of org.eclipse.che.api.project.shared.dto.TreeElement in project che by eclipse.

the class ProjectServiceTest method testGetTree.

@Test
public void testGetTree() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    FolderEntry a = myProject.getBaseFolder().createFolder("a");
    a.createFolder("b/c");
    a.createFolder("x/y");
    a.createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/tree/my_project/a", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    TreeElement tree = (TreeElement) response.getEntity();
    ItemReference a_node = tree.getNode();
    assertEquals(a_node.getName(), "a");
    validateFolderLinks(a_node);
    List<TreeElement> children = tree.getChildren();
    assertNotNull(children);
    assertEquals(children.size(), 2);
    Set<String> names = new LinkedHashSet<>(2);
    for (TreeElement subTree : children) {
        ItemReference _node = subTree.getNode();
        validateFolderLinks(_node);
        names.add(_node.getName());
        // default depth is 1
        Assert.assertTrue(subTree.getChildren().isEmpty());
    }
    Assert.assertTrue(names.contains("b"));
    Assert.assertTrue(names.contains("x"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Test(org.testng.annotations.Test)

Aggregations

TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)6 LinkedHashSet (java.util.LinkedHashSet)4 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)4 ContainerResponse (org.everrest.core.impl.ContainerResponse)4 Test (org.testng.annotations.Test)4 Resource (org.eclipse.che.ide.api.resources.Resource)2 Optional (com.google.common.base.Optional)1 Function (org.eclipse.che.api.promises.client.Function)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)1 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)1 Container (org.eclipse.che.ide.api.resources.Container)1 ProblemProjectMarker (org.eclipse.che.ide.api.resources.Project.ProblemProjectMarker)1 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)1