Search in sources :

Example 76 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class LocalVirtualFileTest method movesFileUnderNewName.

@Test
public void movesFileUnderNewName() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile movedFile = file.moveTo(targetFolder, "new_name", false, null);
    assertionHelper.assertThatMetadataIoFileHasContent(movedFile.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
    assertionHelper.assertThatIoFileHasContent(movedFile.getPath(), DEFAULT_CONTENT_BYTES);
    assertionHelper.assertThatIoFileDoesNotExist(filePath);
    assertionHelper.assertThatMetadataIoFileDoesNotExist(filePath);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 77 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class LocalVirtualFileTest method copiesFile.

@Test
public void copiesFile() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    VirtualFile targetFolder = root.createFolder(generateFolderName());
    VirtualFile copy = file.copyTo(targetFolder);
    assertionHelper.assertThatIoFilesHaveSameContent(file.getPath(), copy.getPath());
    assertionHelper.assertThatMetadataIoFilesHaveSameContent(file.getPath(), copy.getPath());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 78 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class LocalVirtualFileTest method copiesLockedFile.

@Test
public void copiesLockedFile() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.lock(0);
    VirtualFile targetFolder = root.createFolder(generateFolderName());
    VirtualFile copy = file.copyTo(targetFolder);
    assertFalse(copy.isLocked());
    assertionHelper.assertThatIoFilesHaveSameContent(file.getPath(), copy.getPath());
    assertionHelper.assertThatLockIoFileDoesNotExist(copy.getPath());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 79 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class LocalVirtualFileTest method copiesFolderUnderNewName.

@Test
public void copiesFolderUnderNewName() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile copiedFolder = folder.copyTo(targetFolder, "new_name", false);
    VirtualFile copiedFile = copiedFolder.getChild(Path.of(file.getName()));
    assertionHelper.assertThatIoFileExists(copiedFolder.getPath());
    assertionHelper.assertThatIoFilesHaveSameContent(file.getPath(), copiedFile.getPath());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Test(org.junit.Test)

Example 80 with VirtualFile

use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.

the class LocalVirtualFileTest method failsMoveLockedFileWhenLockTokenIsInvalid.

@Test
public void failsMoveLockedFileWhenLockTokenIsInvalid() throws Exception {
    VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
    file.setProperty("property1", "value1");
    Path filePath = file.getPath();
    String invalidLockToken = invalidateLockToken(file.lock(0));
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    Path movedFilePath = targetFolder.getPath().newPath(file.getName());
    try {
        file.moveTo(targetFolder, null, false, invalidLockToken);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertionHelper.assertThatIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatLockIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatMetadataIoFileDoesNotExist(movedFilePath);
        assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
        assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
        assertionHelper.assertThatLockIoFileExists(filePath);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Aggregations

VirtualFile (org.eclipse.che.api.vfs.VirtualFile)321 Test (org.junit.Test)267 Path (org.eclipse.che.api.vfs.Path)62 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)54 ByteArrayInputStream (java.io.ByteArrayInputStream)32 ConflictException (org.eclipse.che.api.core.ConflictException)28 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)27 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)22 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)22 ServerException (org.eclipse.che.api.core.ServerException)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Archiver (org.eclipse.che.api.vfs.Archiver)14 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 OutputStream (java.io.OutputStream)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Map (java.util.Map)5