Search in sources :

Example 16 with NewProjectConfig

use of org.eclipse.che.api.core.model.project.NewProjectConfig 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 17 with NewProjectConfig

use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.

the class ProjectManagerWriteTest method shouldCreateParentFolderAtCreatingProjectWhenParentDoesNotExist.

@Test
public void shouldCreateParentFolderAtCreatingProjectWhenParentDoesNotExist() throws Exception {
    final String nonExistentParentPath = "/rootProject";
    final String innerProjectPath = "/rootProject/innerProject";
    final NewProjectConfig config = createProjectConfigObject(null, innerProjectPath, null, null);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    checkProjectExist(nonExistentParentPath);
    checkProjectExist(innerProjectPath);
    assertEquals(2, projectRegistry.getProjects().size());
}
Also used : ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 18 with NewProjectConfig

use of org.eclipse.che.api.core.model.project.NewProjectConfig 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 19 with NewProjectConfig

use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.

the class ProjectManagerWriteTest method shouldThrowConflictExceptionAtCreatingBatchProjectsWhenProjectWithPathAlreadyExist.

@Test
public void shouldThrowConflictExceptionAtCreatingBatchProjectsWhenProjectWithPathAlreadyExist() throws Exception {
    final String path = "/somePath";
    final NewProjectConfig config = createProjectConfigObject("project", path, BaseProjectType.ID, null);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    checkProjectExist(path);
    assertEquals(1, projectRegistry.getProjects().size());
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("ConflictException should be thrown : Project config with the same path is already exists");
    } catch (ConflictException e) {
        assertEquals(1, projectRegistry.getProjects().size());
    }
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 20 with NewProjectConfig

use of org.eclipse.che.api.core.model.project.NewProjectConfig 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

NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)23 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)14 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)8 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)8 ConflictException (org.eclipse.che.api.core.ConflictException)6 BadRequestException (org.eclipse.che.api.core.BadRequestException)5 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Problem (org.eclipse.che.api.project.server.RegisteredProject.Problem)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)3 ServerException (org.eclipse.che.api.core.ServerException)3 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)3 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 String.format (java.lang.String.format)1 PathMatcher (java.nio.file.PathMatcher)1