Search in sources :

Example 1 with MoveOptions

use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.

the class ProjectServiceTest method testMoveFolderWithRename.

@Test
public void testMoveFolderWithRename() 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()));
    // new name for folder
    final String renamedFolder = "renamedFolder";
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(renamedFolder);
    descriptor.setOverWrite(false);
    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(format("a/b/c/%s/test.txt", renamedFolder)));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Example 2 with MoveOptions

use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.

the class ProjectServiceTest method testMoveFileWithRenameAndOverwrite.

@Test
public void testMoveFileWithRenameAndOverwrite() 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";
    ((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));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(destinationFileName);
    descriptor.setOverWrite(true);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/" + originFileName + "?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/" + destinationFileName));
    // new
    assertNotNull(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName));
    Scanner inputStreamScanner = null;
    String theFirstLineFromDestinationFile;
    try {
        inputStreamScanner = new Scanner(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName).getVirtualFile().getContent());
        theFirstLineFromDestinationFile = inputStreamScanner.nextLine();
        // destination should contain original file's content
        assertEquals(theFirstLineFromDestinationFile, originContent);
    } catch (ForbiddenException | ServerException e) {
        Assert.fail(e.getMessage());
    } finally {
        if (inputStreamScanner != null) {
            inputStreamScanner.close();
        }
    }
}
Also used : Scanner(java.util.Scanner) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Example 3 with MoveOptions

use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.

the class ProjectServiceTest method testMoveFolderWithRenameAndOverwrite.

@Test
public void testMoveFolderWithRenameAndOverwrite() 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 overwritenContent = "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, overwritenContent.getBytes(Charset.defaultCharset()));
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.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(format("a/b/c/%s/test.txt", renamedFolder)));
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Example 4 with MoveOptions

use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.

the class ProjectServiceClientImpl method move.

/** {@inheritDoc} */
@Override
public Promise<Void> move(Path source, Path target, String newName, boolean overwrite) {
    final String url = getBaseUrl() + MOVE + path(source.toString()) + "?to=" + URL.encodeQueryString(target.toString());
    final MoveOptions moveOptions = dtoFactory.createDto(MoveOptions.class);
    moveOptions.setName(newName);
    moveOptions.setOverWrite(overwrite);
    return reqFactory.createPostRequest(url, moveOptions).loader(loaderFactory.newLoader("Moving...")).send();
}
Also used : MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions)

Example 5 with MoveOptions

use of org.eclipse.che.api.project.shared.dto.MoveOptions in project che by eclipse.

the class ProjectServiceTest method testRenameFile.

@Test
public void testRenameFile() throws Exception {
    RegisteredProject myProject = pm.getProject("my_project");
    myProject.getBaseFolder().createFolder("a/b");
    ((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile("test.txt", "to be or not no be".getBytes(Charset.defaultCharset()));
    // name for file after move
    final String destinationName = "copyOfTestForMove.txt";
    Map<String, List<String>> headers = new HashMap<>();
    headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
    MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
    descriptor.setName(destinationName);
    descriptor.setOverWrite(false);
    ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/test.txt", "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/file/my_project/a/b/%s", destinationName)));
    VirtualFileEntry theTargetFile = myProject.getBaseFolder().getChild(format("a/b/%s", destinationName));
    // new
    assertNotNull(theTargetFile);
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Aggregations

MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)7 ArrayList (java.util.ArrayList)6 Collections.singletonList (java.util.Collections.singletonList)6 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 ContainerResponse (org.everrest.core.impl.ContainerResponse)6 Test (org.testng.annotations.Test)6 Scanner (java.util.Scanner)1 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)1 ServerException (org.eclipse.che.api.core.ServerException)1