Search in sources :

Example 16 with ContainerResponse

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"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 17 with ContainerResponse

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);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 18 with ContainerResponse

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"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) Test(org.testng.annotations.Test)

Example 19 with ContainerResponse

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"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CopyOptions(org.eclipse.che.api.project.shared.dto.CopyOptions) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 20 with ContainerResponse

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());
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

ContainerResponse (org.everrest.core.impl.ContainerResponse)69 Test (org.testng.annotations.Test)68 List (java.util.List)35 LinkedList (java.util.LinkedList)34 ArrayList (java.util.ArrayList)33 Collections.singletonList (java.util.Collections.singletonList)33 HashMap (java.util.HashMap)22 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)22 LinkedHashMap (java.util.LinkedHashMap)20 LinkedHashSet (java.util.LinkedHashSet)15 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)12 MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)8 CopyOptions (org.eclipse.che.api.project.shared.dto.CopyOptions)6 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 EntityTag (javax.ws.rs.core.EntityTag)5 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)5 ServerException (org.eclipse.che.api.core.ServerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4