Search in sources :

Example 11 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource.

@Test
public void testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource() throws Exception {
    final String rootProjectPath = "/rootProject";
    final String innerProjectPath = "/rootProject/innerProject";
    final String rootImportType = "rootImportType";
    final String innerImportType = "innerImportType";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(rootImportType, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(innerImportType, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(rootImportType);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(innerImportType);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", innerProjectPath, innerProjectType, source2);
    config2.setAttributes(attributes);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config2);
    configs.add(config1);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    checkProjectExist(rootProjectPath);
    checkChildrenFor(rootProjectFolder, children1);
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(innerProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 12 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method testCreateBatchProjectsByImportingSourceCode.

@Test
public void testCreateBatchProjectsByImportingSourceCode() throws Exception {
    final String projectPath1 = "/testProject1";
    final String projectPath2 = "/testProject2";
    final String importType1 = "importType1";
    final String importType2 = "importType2";
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(importType1, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(importType2, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType1);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", projectPath1, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType2);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", projectPath2, BaseProjectType.ID, source2);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    final RegisteredProject project1 = projectRegistry.getProject(projectPath1);
    final FolderEntry projectFolder1 = project1.getBaseFolder();
    checkProjectExist(projectPath1);
    checkChildrenFor(projectFolder1, children1);
    final RegisteredProject project2 = projectRegistry.getProject(projectPath2);
    final FolderEntry projectFolder2 = project2.getBaseFolder();
    checkProjectExist(projectPath2);
    checkChildrenFor(projectFolder2, children2);
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 13 with SourceStorageDto

use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.

the class ProjectManagerWriteTest method shouldRollbackCreatingBatchProjects.

@Test
public void shouldRollbackCreatingBatchProjects() throws Exception {
    // we should rollback operation of creating batch projects when we have not source code for at least one project
    // For example: two projects were success created, but we could not get source code for third configuration
    // At this use case we should rollback the operation and clean up all created projects
    final String projectPath1 = "/testProject1";
    final String projectPath2 = "/testProject2";
    final String projectPath3 = "/testProject3";
    final String importType1 = "importType1";
    final String importType2 = "importType2";
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(importType1, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(importType2, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType1);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", projectPath1, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType2);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", projectPath2, BaseProjectType.ID, source2);
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfigDto config3 = createProjectConfigObject("testProject3", projectPath3, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    //will be success created
    configs.add(config1);
    //will be success created
    configs.add(config2);
    //we be failed - we have not registered importer - source code will not be imported
    configs.add(config3);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("We should rollback operation of creating batch projects when we could not get source code for at least one project");
    } catch (Exception e) {
        assertEquals(0, projectRegistry.getProjects().size());
        assertNull(projectRegistry.getProject(projectPath1));
        assertNull(pm.getProjectsRoot().getChild(projectPath1));
        assertNull(projectRegistry.getProject(projectPath2));
        assertNull(pm.getProjectsRoot().getChild(projectPath2));
        assertNull(projectRegistry.getProject(projectPath3));
        assertNull(pm.getProjectsRoot().getChild(projectPath3));
    }
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) 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)

Aggregations

SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)13 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)10 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 List (java.util.List)4 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 HashMap (java.util.HashMap)3 BadRequestException (org.eclipse.che.api.core.BadRequestException)3 Promise (org.eclipse.che.api.promises.client.Promise)3 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)2 Function (org.eclipse.che.api.promises.client.Function)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2