Search in sources :

Example 11 with ContainerResponse

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

Example 12 with ContainerResponse

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

Example 13 with ContainerResponse

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");
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) 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) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 14 with ContainerResponse

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

Example 15 with ContainerResponse

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"));
}
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)

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