Search in sources :

Example 61 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileTest method failsMoveFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile.

@Test
public void failsMoveFolderWhenTargetFolderNeedBeOverwrittenButContainsLockedFile() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile conflictFolder = targetFolder.createFolder(folder.getName());
    VirtualFile lockedFileInConflictFolder = conflictFolder.createFile(generateFileName(), "xxx");
    lockedFileInConflictFolder.lock(0);
    try {
        folder.moveTo(targetFolder, null, true, null);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertionHelper.assertThatIoFileHasContent(lockedFileInConflictFolder.getPath(), "xxx".getBytes());
        assertionHelper.assertThatIoFileDoesNotExist(conflictFolder.getPath().newPath(file.getName()));
        assertionHelper.assertThatIoFileExists(folder.getPath());
        assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 62 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStreamWithoutLockToken.

@Test
public void failsUpdateContentOfLockedFileByStreamWithoutLockToken() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.lock(0);
    try {
        file.updateContent(new ByteArrayInputStream("updated content".getBytes()));
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 63 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileTest method failsCreateFileWhenParenIsNotFolder.

@Test
public void failsCreateFileWhenParenIsNotFolder() throws Exception {
    VirtualFile parent = getRoot().createFile("parent", "");
    try {
        parent.createFile("file", DEFAULT_CONTENT);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertionHelper.assertThatIoFileDoesNotExist(parent.getPath().newPath("file"));
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 64 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileTest method failsUnlockFileWhenLockTokenIsInvalid.

@Test
public void failsUnlockFileWhenLockTokenIsInvalid() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    String invalidLockToken = invalidateLockToken(file.lock(0));
    try {
        file.unlock(invalidLockToken);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertionHelper.assertThatLockIoFileExists(file.getPath());
        assertTrue(file.isLocked());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 65 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileTest method failsMoveFolderWhenItContainsLockedFile.

@Test
public void failsMoveFolderWhenItContainsLockedFile() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile lockedFile = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    lockedFile.lock(0);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    Path movedFolderPath = targetFolder.getPath().newPath(folder.getName());
    try {
        folder.moveTo(targetFolder);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException e) {
        assertionHelper.assertThatIoFileDoesNotExist(movedFolderPath);
        assertionHelper.assertThatIoFileExists(folder.getPath());
        assertionHelper.assertThatIoFileExists(lockedFile.getPath());
        assertionHelper.assertThatLockIoFileExists(lockedFile.getPath());
    }
}
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

ForbiddenException (org.eclipse.che.api.core.ForbiddenException)88 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)54 Test (org.junit.Test)44 ServerException (org.eclipse.che.api.core.ServerException)33 Path (org.eclipse.che.api.vfs.Path)29 ConflictException (org.eclipse.che.api.core.ConflictException)25 IOException (java.io.IOException)13 NotFoundException (org.eclipse.che.api.core.NotFoundException)12 File (java.io.File)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 List (java.util.List)6 BadRequestException (org.eclipse.che.api.core.BadRequestException)6 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 ApiResponses (io.swagger.annotations.ApiResponses)3