use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCopyFolder.
@Test
public void testCopyFolder() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/copy/my_project/a/b?to=/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/b"));
assertNotNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
assertNotNull(myProject.getBaseFolder().getChild("a/b/c/b/test.txt"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetProjectCheckUserPermissions.
@Test
public void testGetProjectCheckUserPermissions() throws Exception {
// Without roles Collections.<String>emptySet() should get default set of permissions
env.setSubject(new SubjectImpl(vfsUser, vfsUser, "dummy_token", false));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/my_project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
assertNotNull(result);
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testDeleteFolder.
@Test
public void testDeleteFolder() throws Exception {
pm.getProject("my_project").getBaseFolder().createFolder("test");
ContainerResponse response = launcher.service(DELETE, "http://localhost:8080/api/project/my_project/test", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 204, "Error: " + response.getEntity());
Assert.assertNull(pm.getProject("my_project").getBaseFolder().getChild("test"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testCopyFileWithRename.
@Test
public void testCopyFileWithRename() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
CopyOptions descriptor = DtoFactory.getInstance().createDto(CopyOptions.class);
descriptor.setName("copyOfTest.txt");
descriptor.setOverWrite(false);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/copy/my_project/a/b/test.txt?to=/my_project/a/b/c", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/file/my_project/a/b/c/copyOfTest.txt"));
// new
assertNotNull(myProject.getBaseFolder().getChild("a/b/c/copyOfTest.txt"));
// old
assertNotNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
}
use of org.everrest.core.impl.ContainerResponse in project che by eclipse.
the class ProjectServiceTest method testGetProjects.
@Test
@SuppressWarnings("unchecked")
public void testGetProjects() throws Exception {
List<RegisteredProject> p = pm.getProjects();
assertEquals(p.size(), 1);
vfsProvider.getVirtualFileSystem().getRoot().createFolder("not_project");
// to refresh
projectRegistry.initProjects();
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
List<ProjectConfigDto> result = (List<ProjectConfigDto>) response.getEntity();
assertNotNull(result);
assertEquals(result.size(), 2);
int good, bad;
if (result.get(0).getName().equals("my_project")) {
good = 0;
bad = 1;
} else {
good = 1;
bad = 0;
}
ProjectConfigDto projectDescriptor = result.get(good);
assertEquals(projectDescriptor.getName(), "my_project");
assertEquals(projectDescriptor.getDescription(), "my test project");
assertEquals(projectDescriptor.getType(), "my_project_type");
ProjectConfigDto badProject = result.get(bad);
assertEquals(badProject.getName(), "not_project");
assertNotNull(badProject.getProblems());
}
Aggregations