Search in sources :

Example 41 with VirtualFile

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

the class SubversionProjectImporterTest method testInvalidImportSources.

/**
     * Test for {@link SubversionProjectImporter#importSources(org.eclipse.che.api.project.server.FolderEntry, org.eclipse.che.api.core.model.project.SourceStorage, org.eclipse.che.api.core.util.LineConsumerFactory)}
     * invalid url.
     *
     * @throws Exception if anything goes wrong
     */
@Test
public void testInvalidImportSources() throws Exception {
    final String projectName = NameGenerator.generate("project-", 3);
    //root.getChild(org.eclipse.che.api.vfs.Path.of(projectName));
    final VirtualFile virtualFile = root.createFolder(projectName);
    FolderEntry projectFolder = new FolderEntry(virtualFile);
    try {
        String fakeUrl = Paths.get(repoRoot.getAbsolutePath()).toUri() + "fake";
        when(sourceStorage.getLocation()).thenReturn(fakeUrl);
        projectImporter.importSources(projectFolder, sourceStorage, new TestUtils.SystemOutLineConsumerFactory());
        fail("The code above should had failed");
    } catch (SubversionException e) {
        final String message = e.getMessage();
        boolean assertBoolean = Pattern.matches("svn: (E[0-9]{6}: )?URL 'file://.*/fake' doesn't exist\n?", message.trim());
        assertTrue(message, assertBoolean);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) TestUtils(org.eclipse.che.plugin.svn.server.utils.TestUtils) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) Test(org.junit.Test)

Example 42 with VirtualFile

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

the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByBytesWithoutLockToken.

@Test
public void failsUpdateContentOfLockedFileByBytesWithoutLockToken() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    file.lock(0);
    try {
        file.updateContent("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) Test(org.junit.Test)

Example 43 with VirtualFile

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

the class LocalVirtualFileTest method getsContentAsStream.

@Test
public void getsContentAsStream() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
    byte[] bytes;
    try (InputStream content = file.getContent()) {
        bytes = ByteStreams.toByteArray(content);
    }
    assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
    assertEquals(DEFAULT_CONTENT, new String(bytes));
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 44 with VirtualFile

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

the class LocalVirtualFileTest method getFileTreeAsList.

private List<VirtualFile> getFileTreeAsList(VirtualFile rootOfTree) throws Exception {
    List<VirtualFile> list = newArrayList();
    rootOfTree.accept(new VirtualFileVisitor() {

        @Override
        public void visit(VirtualFile virtualFile) throws ServerException {
            list.add(virtualFile);
            if (virtualFile.isFolder()) {
                for (VirtualFile child : virtualFile.getChildren()) {
                    child.accept(this);
                }
            }
        }
    });
    return list;
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor)

Example 45 with VirtualFile

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

the class LocalVirtualFileTest method folderContentLengthIsZero.

@Test
public void folderContentLengthIsZero() throws Exception {
    VirtualFile root = getRoot();
    VirtualFile folder = root.createFolder(generateFolderName());
    assertEquals(0, folder.getLength());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) 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