use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testExportZip.
@Test
public void testExportZip() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b").createFile("test.txt", "hello".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/export/my_project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
assertEquals(response.getContentType().toString(), ExtMediaType.APPLICATION_ZIP);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCreatePath.
@Test
public void testCreatePath() throws Exception {
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/folder/my_project/a/b/c", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/children/my_project/a/b/c"));
VirtualFileEntry folder = pm.getProject("my_project").getBaseFolder().getChild("a/b/c");
Assert.assertTrue(folder.isFolder());
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testUpdateBadProject.
@Test
public void testUpdateBadProject() throws Exception {
//MountPoint mountPoint = pm.getProjectsRoot(workspace).getVirtualFile().getMountPoint();
//mountPoint.getRoot().createFolder("not_project");
pm.getProjectsRoot().createFolder("not_project");
projectRegistry.initProjects();
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
Map<String, List<String>> attributeValues = new LinkedHashMap<>();
attributeValues.put("my_attribute", singletonList("to be or not to be"));
ProjectConfigDto descriptor = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType("my_project_type").withDescription("updated project").withAttributes(attributeValues);
final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/not_project").withName("not_project").withDescription("updated project").withType("my_project_type").withAttributes(attributeValues).withSource(DtoFactory.getInstance().createDto(SourceStorageDto.class));
projects.add(newProjectConfig);
ContainerResponse response = launcher.service(PUT, "http://localhost:8080/api/project/not_project", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
RegisteredProject project = pm.getProject("not_project");
assertNotNull(project);
//ProjectConfig description = project.getConfig();
assertEquals(project.getDescription(), "updated project");
assertEquals(project.getProjectType().getId(), "my_project_type");
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testUpdateFileContent.
@Test
public void testUpdateFileContent() throws Exception {
String myContent = "<test>hello</test>";
pm.getProject("my_project").getBaseFolder().createFile("test.xml", "to be or not to be".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(PUT, "http://localhost:8080/api/project/file/my_project/test.xml", "http://localhost:8080/api", null, myContent.getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
VirtualFileEntry file = pm.getProject("my_project").getBaseFolder().getChild("test.xml");
Assert.assertTrue(file.isFile());
FileEntry _file = (FileEntry) file;
assertEquals(new String(_file.contentAsBytes()), myContent);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetTreeWithDepthAndIncludeFilesNoFiles.
@Test
public void testGetTreeWithDepthAndIncludeFilesNoFiles() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
FolderEntry a = myProject.getBaseFolder().createFolder("a");
a.createFolder("b/c");
a.createFolder("x");
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/tree/my_project/a?depth=100&includeFiles=true", "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.assertFalse(names.contains("x/test.txt"));
}
Aggregations