use of org.everrest.core.impl.ContainerResponse 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);
}
use of org.everrest.core.impl.ContainerResponse 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"));
}
use of org.everrest.core.impl.ContainerResponse 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"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCreateFolderInRoot.
// any folder created in the root of the workspace automatically becomes project
@Test
public void testCreateFolderInRoot() throws Exception {
String folder = "my_folder";
ContainerResponse response = launcher.service(POST, format("http://localhost:8080/api/project/folder/%s", folder), "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
ItemReference fileItem = (ItemReference) response.getEntity();
assertEquals(fileItem.getType(), "project");
assertEquals(fileItem.getName(), folder);
assertEquals(fileItem.getPath(), "/" + folder);
validateFolderLinks(fileItem);
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create(format("http://localhost:8080/api/project/children/%s", folder)));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetChildren.
@Test
@SuppressWarnings("unchecked")
public void testGetChildren() 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/children/my_project/a", "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> names = new LinkedHashSet<>(2);
names.addAll(result.stream().map(ItemReference::getName).collect(Collectors.toList()));
Assert.assertTrue(names.contains("b"));
Assert.assertTrue(names.contains("test.txt"));
}
Aggregations