Search in sources :

Example 16 with ItemReference

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

the class ProjectServiceTest method testGetTreeWithDepth.

@Test
public void testGetTreeWithDepth() 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?depth=2", "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");
    List<TreeElement> children = tree.getChildren();
    assertNotNull(children);
    Set<String> names = new LinkedHashSet<>(4);
    for (TreeElement subTree : children) {
        ItemReference _node = subTree.getNode();
        validateFolderLinks(_node);
        String name = _node.getName();
        names.add(name);
        for (TreeElement subSubTree : subTree.getChildren()) {
            ItemReference __node = subSubTree.getNode();
            validateFolderLinks(__node);
            names.add(name + "/" + __node.getName());
        }
    }
    Assert.assertTrue(names.contains("b"));
    Assert.assertTrue(names.contains("x"));
    Assert.assertTrue(names.contains("b/c"));
    Assert.assertTrue(names.contains("x/y"));
}
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)

Example 17 with ItemReference

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

the class ProjectServiceTest method testGetItemWithoutParentProject.

@Test
public void testGetItemWithoutParentProject() throws Exception {
    FolderEntry a = pm.getProjectsRoot().createFolder("a");
    a.createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/item/a/test.txt", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ItemReference result = (ItemReference) response.getEntity();
    assertEquals(result.getType(), "file");
//assertEquals(result.getMediaType(), TEXT_PLAIN);
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 18 with ItemReference

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

the class ProjectServiceTest method testGetItem.

@Test
@SuppressWarnings("unchecked")
public void testGetItem() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    FolderEntry a = myProject.getBaseFolder().createFolder("a");
    a.createFolder("b");
    a.createFile("test.txt", "test".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/item/my_project/a/b", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ItemReference result = (ItemReference) response.getEntity();
    assertEquals(result.getName(), "b");
    response = launcher.service(GET, "http://localhost:8080/api/project/item/my_project/a/test.txt", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    result = (ItemReference) response.getEntity();
    assertEquals(result.getType(), "file");
//assertEquals(result.getMediaType(), TEXT_PLAIN);
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 19 with ItemReference

use of org.eclipse.che.api.project.shared.dto.ItemReference 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)

Example 20 with ItemReference

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

the class ProjectServiceTest method testSearchByText.

@SuppressWarnings("unchecked")
@Test
public void testSearchByText() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "hello".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("x/y").createFile("__test.txt", "searchhit".getBytes(Charset.defaultCharset()));
    myProject.getBaseFolder().createFolder("c").createFile("_test", "searchhit".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/search/my_project?text=searchhit", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    List<ItemReference> result = (List<ItemReference>) response.getEntity();
    assertEquals(result.size(), 2);
    Set<String> paths = new LinkedHashSet<>(1);
    paths.addAll(result.stream().map(ItemReference::getPath).collect(Collectors.toList()));
    Assert.assertTrue(paths.contains("/my_project/x/y/__test.txt"));
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) LinkedHashSet(java.util.LinkedHashSet) ContainerResponse(org.everrest.core.impl.ContainerResponse) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)26 Test (org.testng.annotations.Test)22 ContainerResponse (org.everrest.core.impl.ContainerResponse)20 ArrayList (java.util.ArrayList)14 LinkedHashSet (java.util.LinkedHashSet)13 List (java.util.List)13 Collections.singletonList (java.util.Collections.singletonList)11 LinkedList (java.util.LinkedList)11 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)4 Link (org.eclipse.che.api.core.rest.shared.dto.Link)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Command (com.google.gwt.user.client.Command)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 Function (org.eclipse.che.api.promises.client.Function)1