use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileTest method failsMoveFileWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled.
@Test
public void failsMoveFileWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled() throws Exception {
VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
Path filePath = file.getPath();
VirtualFile existedFile = targetFolder.createFile("existed_name", "existed content");
try {
file.moveTo(targetFolder, "existed_name", false, null);
thrown.expect(ConflictException.class);
} catch (ConflictException e) {
assertEquals(file, getRoot().getChild(filePath));
assertEquals("existed content", existedFile.getContentAsString());
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileTest method failsRenameFileWhenFolderContainsItemWithSameName.
@Test
public void failsRenameFileWhenFolderContainsItemWithSameName() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
Path filePath = file.getPath();
file.setProperty("property1", "value1");
VirtualFile conflictFile = folder.createFile("existed_name", "xxx");
Path conflictFilePath = conflictFile.getPath();
conflictFile.setProperty("property2", "value2");
try {
file.rename("existed_name");
thrown.expect(ConflictException.class);
} catch (ConflictException e) {
assertionHelper.assertThatIoFileHasContent(conflictFilePath, "xxx".getBytes());
assertionHelper.assertThatMetadataIoFileHasContent(conflictFilePath, serializeVirtualFileMetadata(ImmutableMap.of("property2", "value2")));
assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class MemoryVirtualFileTest method failsCopyFolderUnderNewNameWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled.
@Test
public void failsCopyFolderUnderNewNameWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
VirtualFile conflictFolder = targetFolder.createFolder("new_name");
try {
folder.copyTo(targetFolder, "new_name", false);
thrown.expect(ConflictException.class);
} catch (ConflictException expected) {
assertNull(getRoot().getChild(conflictFolder.getPath().newPath(file.getName())));
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileTest method failsCopyFileWhenItemWithTheSameNameExistsInTargetFolderAndOverwritingIsDisabled.
@Test
public void failsCopyFileWhenItemWithTheSameNameExistsInTargetFolderAndOverwritingIsDisabled() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
VirtualFile targetFolder = root.createFolder(generateFolderName());
VirtualFile conflictFile = targetFolder.createFile("existed_name", "xxx");
try {
file.copyTo(targetFolder, "existed_name", false);
thrown.expect(ConflictException.class);
} catch (ConflictException e) {
assertionHelper.assertThatIoFileHasContent(conflictFile.getPath(), "xxx".getBytes());
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileTest method failsMoveFolderWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled.
@Test
public void failsMoveFolderWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled() 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());
try {
folder.moveTo(targetFolder);
thrown.expect(ConflictException.class);
} catch (ConflictException expected) {
assertionHelper.assertThatIoFileDoesNotExist(conflictFolder.getPath().newPath(file.getName()));
assertionHelper.assertThatIoFileExists(folder.getPath());
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
Aggregations