Search in sources :

Example 1 with ProjectImportOutputWSLineConsumer

use of org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer in project che by eclipse.

the class ProjectManagerWriteTest method testImportProject.

@Test
public void testImportProject() throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    String fileContent = "to be or not to be";
    ZipOutputStream zipOut = new ZipOutputStream(bout);
    zipOut.putNextEntry(new ZipEntry("folder1/"));
    zipOut.putNextEntry(new ZipEntry("folder1/file1.txt"));
    zipOut.putNextEntry(new ZipEntry("file1"));
    zipOut.write(fileContent.getBytes());
    zipOut.close();
    final InputStream zip = new ByteArrayInputStream(bout.toByteArray());
    final String importType = "_123_";
    registerImporter(importType, zip);
    SourceStorage sourceConfig = DtoFactory.newDto(SourceStorageDto.class).withType(importType);
    pm.importProject("/testImportProject", sourceConfig, false, () -> new ProjectImportOutputWSLineConsumer("BATCH", "ws", 300));
    RegisteredProject project = projectRegistry.getProject("/testImportProject");
    assertNotNull(project);
    // BASE
    //System.out.println(">>> "+project.getProjectType());
    assertNotNull(project.getBaseFolder().getChild("file1"));
    assertEquals(fileContent, project.getBaseFolder().getChild("file1").getVirtualFile().getContentAsString());
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProjectImportOutputWSLineConsumer(org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer) Test(org.junit.Test)

Example 2 with ProjectImportOutputWSLineConsumer

use of org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer in project che by eclipse.

the class ProjectManagerWriteTest method testRemoveFolderForSourcesWhenImportingProjectIsFailed.

@Test
public void testRemoveFolderForSourcesWhenImportingProjectIsFailed() throws Exception {
    final String projectPath = "/testImportProject";
    final String importType = "_123_";
    registerImporter(importType, null);
    SourceStorage sourceConfig = DtoFactory.newDto(SourceStorageDto.class).withType(importType);
    try {
        pm.importProject(projectPath, sourceConfig, false, () -> new ProjectImportOutputWSLineConsumer("testImportProject", "ws", 300));
    } catch (Exception e) {
    }
    boolean projectFolderExist = vfsProvider.getVirtualFileSystem().getRoot().hasChild(Path.of(projectPath));
    assertFalse(projectFolderExist);
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ProjectImportOutputWSLineConsumer(org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Example 3 with ProjectImportOutputWSLineConsumer

use of org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer in project che by eclipse.

the class ProjectManagerWriteTest method testImportProjectWithoutImporterFailed.

@Test
public void testImportProjectWithoutImporterFailed() throws Exception {
    SourceStorage sourceConfig = DtoFactory.newDto(SourceStorageDto.class).withType("nothing");
    try {
        pm.importProject("/testImportProject", sourceConfig, false, () -> new ProjectImportOutputWSLineConsumer("testImportProject", "ws", 300));
        fail("NotFoundException: Unable import sources project from 'null'. Sources type 'nothing' is not supported.");
    } catch (NotFoundException e) {
    }
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectImportOutputWSLineConsumer(org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer) Test(org.junit.Test)

Aggregations

SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)3 ProjectImportOutputWSLineConsumer (org.eclipse.che.api.project.server.importer.ProjectImportOutputWSLineConsumer)3 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)3 Test (org.junit.Test)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)1 ServerException (org.eclipse.che.api.core.ServerException)1