Search in sources :

Example 11 with NewProjectConfig

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

the class ProjectManagerWriteTest method testCreateProjectWhenSourceCodeIsNotReachable.

@Test
public void testCreateProjectWhenSourceCodeIsNotReachable() throws Exception {
    final String projectPath = "/testProject";
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfigDto config = createProjectConfigObject("testProject1", projectPath, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("Exception should be thrown when source code is not reachable");
    } catch (Exception e) {
        assertEquals(0, projectRegistry.getProjects().size());
        assertNull(projectRegistry.getProject(projectPath));
        assertNull(pm.getProjectsRoot().getChild(projectPath));
    }
}
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)

Example 12 with NewProjectConfig

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

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProject.

@Test
public void testCreateBatchProjectsWithInnerProject() throws Exception {
    final String rootProjectPath = "/testProject1";
    final String innerProjectPath = "/testProject1/innerProject";
    final String importType = "importType1";
    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 String[] paths2 = { "innerProject/", "innerProject/folder2/", "innerProject/folder2/file2.txt" };
    final List<String> children1 = Arrays.asList(paths1);
    final List<String> children2 = Arrays.asList(paths2);
    final List<String> children = new ArrayList<>(children1);
    children.addAll(children2);
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType);
    NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source);
    NewProjectConfigDto config2 = createProjectConfigObject("innerProject", innerProjectPath, innerProjectType, null);
    config2.setAttributes(attributes);
    List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(rootProject);
    assertTrue(rootProjectFolder.getVirtualFile().exists());
    assertEquals(rootProjectPath, rootProject.getPath());
    checkChildrenFor(rootProjectFolder, children1);
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(rootProjectFolder, 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 13 with NewProjectConfig

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

the class ProjectManagerWriteTest method testCreateProjectWithInvalidAttribute.

@Test
public void testCreateProjectWithInvalidAttribute() throws Exception {
    // SPECS:
    // Project will be created with problem code = 13(Value for required attribute is not initialized)
    // when required attribute is not initialized
    final String path = "/testCreateProjectInvalidAttributes";
    final String projectType = "pt2";
    final NewProjectConfig config = new NewProjectConfigImpl(path, projectType, null, "name", "descr", null, null, null);
    pm.createProject(config, null);
    RegisteredProject project = projectRegistry.getProject(path);
    assertNotNull(project);
    assertNotNull(pm.getProjectsRoot().getChild(path));
    assertEquals(projectType, project.getType());
    List<Problem> problems = project.getProblems();
    assertNotNull(problems);
    assertFalse(problems.isEmpty());
    assertEquals(1, problems.size());
    assertEquals(13, problems.get(0).code);
}
Also used : Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 14 with NewProjectConfig

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

the class ProjectManagerWriteTest method shouldCreateBatchProjectsWithoutMixinPTWhenThisOneIsUnregistered.

@Test
public void shouldCreateBatchProjectsWithoutMixinPTWhenThisOneIsUnregistered() throws Exception {
    // If declared mixin PT is not registered, project is created w/o it, with Problem 12
    final String projectPath = "/testProject";
    final String mixinPType = "unregistered";
    final NewProjectConfig config = createProjectConfigObject("projectName", projectPath, BaseProjectType.ID, null);
    config.getMixins().add(mixinPType);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    final RegisteredProject project = projectRegistry.getProject(projectPath);
    final List<Problem> problems = project.getProblems();
    checkProjectExist(projectPath);
    assertEquals(1, problems.size());
    assertEquals(12, problems.get(0).code);
    assertTrue(project.getMixins().isEmpty());
    assertEquals(1, projectRegistry.getProjects().size());
}
Also used : ArrayList(java.util.ArrayList) Problem(org.eclipse.che.api.project.server.RegisteredProject.Problem) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 15 with NewProjectConfig

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

the class ProjectManagerWriteTest method testCreateBatchProjectsWhenConfigContainsOnlyPath.

@Test
public void testCreateBatchProjectsWhenConfigContainsOnlyPath() throws Exception {
    // NewProjectConfig object contains only one mandatory Project Path field
    final String projectPath1 = "/testProject1";
    final String projectPath2 = "/testProject2";
    final NewProjectConfig config1 = createProjectConfigObject(null, projectPath1, null, null);
    final NewProjectConfig config2 = createProjectConfigObject(null, projectPath2, null, null);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    checkProjectExist(projectPath1);
    checkProjectExist(projectPath2);
    assertEquals(2, projectRegistry.getProjects().size());
}
Also used : ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) 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