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);
}
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);
}
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));
}
}
Aggregations