Search in sources :

Example 81 with ForbiddenException

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

the class MemoryVirtualFileTest 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) {
        assertEquals("xxx", lockedFileInConflictFolder.getContentAsString());
        assertNull(getRoot().getChild(conflictFolder.getPath().newPath(file.getName())));
        assertNotNull(getRoot().getChild(folder.getPath()));
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 82 with ForbiddenException

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

the class MemoryVirtualFileTest 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) {
        assertNull(getRoot().getChild(movedFolderPath.newPath(lockedFile.getName())));
        assertNull(getRoot().getChild(movedFolderPath));
        assertNotNull(getRoot().getChild(folder.getPath()));
        assertEquals(DEFAULT_CONTENT, lockedFile.getContentAsString());
    }
}
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)

Example 83 with ForbiddenException

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

the class MemoryVirtualFileTest method failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid.

@Test
public void failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    String invalidLockToken = invalidateLockToken(file.lock(0));
    try {
        file.updateContent("updated content".getBytes(), invalidLockToken);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 84 with ForbiddenException

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

the class MemoryVirtualFileTest 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) {
        assertNull(getRoot().getChild(movedFilePath));
        assertTrue(file.isLocked());
        assertEquals(file, getRoot().getChild(filePath));
        assertEquals(ImmutableMap.of("property1", "value1"), file.getProperties());
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
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)

Example 85 with ForbiddenException

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

the class MemoryVirtualFileTest 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) {
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ByteArrayInputStream(java.io.ByteArrayInputStream) 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