Search in sources :

Example 21 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testUpdateProject.

@Test
public void testUpdateProject() throws Exception {
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Content-Type", singletonList(APPLICATION_JSON));
    ProjectTypeDef pt = new ProjectTypeDef("testUpdateProject", "my project type", true, false) {
    };
    ptRegistry.registerProjectType(pt);
    pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withDescription("created project").withType("testUpdateProject").withPath("/testUpdateProject"), null);
    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).withName("module1").withType("testUpdateProject").withDescription("updated project").withAttributes(attributeValues);
    ContainerResponse response = launcher.service(PUT, "http://localhost:8080/api/project/testUpdateProject", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    RegisteredProject project = pm.getProject("/testUpdateProject");
    assertNotNull(project);
    //ProjectConfig config = project.getConfig();
    assertEquals(project.getDescription(), "updated project");
    assertEquals(project.getProjectType().getId(), "testUpdateProject");
}
Also used : 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) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 22 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testGetProject.

@Test
public void testGetProject() throws Exception {
    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);
    assertEquals(result.getDescription(), "my test project");
    assertEquals(result.getType(), "my_project_type");
    Map<String, List<String>> attributes = result.getAttributes();
    assertNotNull(attributes);
    assertEquals(attributes.size(), 1);
    assertEquals(attributes.get("my_attribute"), singletonList("attribute value 1"));
    validateProjectLinks(result);
}
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)

Example 23 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testCopyFolderWithRenameAndOverwrite.

@Test
public void testCopyFolderWithRenameAndOverwrite() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b/c");
    // File names
    String originFileName = "test.txt";
    String destinationFileName = "overwriteMe.txt";
    // File contents
    String originContent = "to be or not no be";
    String overwrittenContent = "that is the question";
    // new name for folder
    final String renamedFolder = "renamedFolder";
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwrittenContent.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(renamedFolder);
    descriptor.setOverWrite(true);
    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", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
    assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
    assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create(format("http://localhost:8080/api/project/children/my_project/a/b/c/%s", renamedFolder)));
    assertNotNull(myProject.getBaseFolder().getChild("a/b/test.txt"));
    assertNotNull(myProject.getBaseFolder().getChild(format("a/b/c/%s/test.txt", renamedFolder)));
    assertEquals(myProject.getBaseFolder().getChild("a/b/test.txt").getName(), myProject.getBaseFolder().getChild(format("a/b/c/%s/%s", renamedFolder, originFileName)).getName());
}
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 24 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testCreateProject.

@Test
public void testCreateProject() throws Exception {
    final String projectName = "new_project";
    final String projectType = "testCreateProject";
    phRegistry.register(createProjectHandlerFor(projectName, projectType));
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("Content-Type", singletonList(APPLICATION_JSON));
    ProjectTypeDef pt = new ProjectTypeDef("testCreateProject", "my project type", true, false) {

        {
            addConstantDefinition("new_project_attribute", "attr description", "to be or not to be");
        }
    };
    ptRegistry.registerProjectType(pt);
    Map<String, List<String>> attributeValues = new LinkedHashMap<>();
    attributeValues.put("new_project_attribute", singletonList("to be or not to be"));
    final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/new_project").withName(projectName).withDescription("new project").withType(projectType).withAttributes(attributeValues).withSource(DtoFactory.getInstance().createDto(SourceStorageDto.class));
    projects.add(newProjectConfig);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(newProjectConfig).getBytes(Charset.defaultCharset()), null);
    assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
    ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
    assertNotNull(result);
    assertEquals(result.getName(), projectName);
    assertEquals(result.getPath(), "/new_project");
    assertEquals(result.getDescription(), newProjectConfig.getDescription());
    assertEquals(result.getType(), newProjectConfig.getType());
    assertEquals(result.getType(), projectType);
    Map<String, List<String>> attributes = result.getAttributes();
    assertNotNull(attributes);
    assertEquals(attributes.size(), 1);
    assertEquals(attributes.get("new_project_attribute"), singletonList("to be or not to be"));
    validateProjectLinks(result);
    RegisteredProject project = pm.getProject("new_project");
    assertNotNull(project);
    //ProjectConfig config = project.getConfig();
    assertEquals(project.getDescription(), newProjectConfig.getDescription());
    assertEquals(project.getProjectType().getId(), newProjectConfig.getType());
    String attributeVal = project.getAttributeEntries().get("new_project_attribute").getString();
    assertNotNull(attributeVal);
    assertEquals(attributeVal, "to be or not to be");
    assertNotNull(project.getBaseFolder().getChild("a"));
    assertNotNull(project.getBaseFolder().getChild("b"));
    assertNotNull(project.getBaseFolder().getChild("test.txt"));
}
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) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 25 with ContainerResponse

use of org.everrest.core.impl.ContainerResponse in project che by eclipse.

the class ProjectServiceTest method testDeleteFile.

@Test
public void testDeleteFile() throws Exception {
    pm.getProject("my_project").getBaseFolder().createFile("test.txt", "to be or not to be".getBytes(Charset.defaultCharset()));
    ContainerResponse response = launcher.service(DELETE, "http://localhost:8080/api/project/my_project/test.txt", "http://localhost:8080/api", null, null, null);
    assertEquals(response.getStatus(), 204, "Error: " + response.getEntity());
    Assert.assertNull(pm.getProject("my_project").getBaseFolder().getChild("test.txt"));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) 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