use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ProjectServiceTest method testGetNotValidProject.
@Test
public void testGetNotValidProject() throws Exception {
//MountPoint mountPoint = pm.getProjectsRoot(workspace).getVirtualFile().getMountPoint();
vfsProvider.getVirtualFileSystem().getRoot().createFolder("not_project");
// to refresh
projectRegistry.initProjects();
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/not_project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
ProjectConfigDto badProject = (ProjectConfigDto) response.getEntity();
assertNotNull(badProject);
assertEquals(badProject.getName(), "not_project");
assertNotNull(badProject.getProblems());
assertTrue(badProject.getProblems().size() > 0);
assertEquals(11, badProject.getProblems().get(0).getCode());
validateProjectLinks(badProject);
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ProjectServiceTest method addMockedProjectConfigDto.
private void addMockedProjectConfigDto(org.eclipse.che.api.project.server.type.ProjectTypeDef myProjectType, String projectName) throws ForbiddenException, ServerException, NotFoundException, ConflictException {
final ProjectConfigDto testProjectConfigMock = mock(ProjectConfigDto.class);
when(testProjectConfigMock.getPath()).thenReturn("/" + projectName);
when(testProjectConfigMock.getName()).thenReturn(projectName);
when(testProjectConfigMock.getDescription()).thenReturn("my test project");
when(testProjectConfigMock.getType()).thenReturn("my_project_type");
when(testProjectConfigMock.getSource()).thenReturn(DtoFactory.getInstance().createDto(SourceStorageDto.class));
// when(testProjectConfigMock.getModules()).thenReturn(modules);
// when(testProjectConfigMock.findModule(anyString())).thenReturn(testProjectConfigMock);
Map<String, List<String>> attr = new HashMap<>();
for (Attribute attribute : myProjectType.getAttributes()) {
attr.put(attribute.getName(), attribute.getValue().getList());
}
when(testProjectConfigMock.getAttributes()).thenReturn(attr);
projects.add(testProjectConfigMock);
pm.createProject(testProjectConfigMock, null);
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ProjectServiceTest method testCreateBatchProjects.
@Test
public void testCreateBatchProjects() throws Exception {
//prepare first project
final String projectName1 = "testProject1";
final String projectTypeId1 = "testProjectType1";
final String projectPath1 = "/testProject1";
createTestProjectType(projectTypeId1);
phRegistry.register(createProjectHandlerFor(projectName1, projectTypeId1));
//prepare inner project
final String innerProjectName = "innerProject";
final String innerProjectTypeId = "testProjectType2";
final String innerProjectPath = "/testProject1/innerProject";
createTestProjectType(innerProjectTypeId);
phRegistry.register(createProjectHandlerFor(innerProjectName, innerProjectTypeId));
//prepare project to import
final String importProjectName = "testImportProject";
final String importProjectTypeId = "testImportProjectType";
final String importProjectPath = "/testImportProject";
final String importType = "importType";
final String[] paths = { "a", "b", "test.txt" };
final List<String> children = new ArrayList<>(Arrays.asList(paths));
registerImporter(importType, prepareZipArchiveBasedOn(children));
createTestProjectType(importProjectTypeId);
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
try (InputStream content = getClass().getResourceAsStream("batchNewProjectConfigs.json")) {
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/batch", "http://localhost:8080/api", headers, ByteStreams.toByteArray(content), null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
final List<ProjectConfigDto> result = (List<ProjectConfigDto>) response.getEntity();
assertNotNull(result);
assertEquals(result.size(), 3);
final ProjectConfigDto importProjectConfig = result.get(0);
checkProjectIsCreated(importProjectName, importProjectPath, importProjectTypeId, importProjectConfig);
final ProjectConfigDto config1 = result.get(1);
checkProjectIsCreated(projectName1, projectPath1, projectTypeId1, config1);
final ProjectConfigDto innerProjectConfig = result.get(2);
checkProjectIsCreated(innerProjectName, innerProjectPath, innerProjectTypeId, innerProjectConfig);
}
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ProjectServiceTest method testImportProject.
@Test
public void testImportProject() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(bout);
zipOut.putNextEntry(new ZipEntry("folder1/"));
zipOut.putNextEntry(new ZipEntry("folder1/file1.txt"));
zipOut.write("to be or not to be".getBytes(Charset.defaultCharset()));
zipOut.close();
final InputStream zip = new ByteArrayInputStream(bout.toByteArray());
final String importType = "_123_";
registerImporter(importType, zip);
final String myType = "chuck_project_type";
final ProjectConfigDto newProjectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/new_project").withName("new_project").withDescription("import test").withType(myType);
projects.add(newProjectConfig);
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", singletonList(APPLICATION_JSON));
String json = "{\n" + " \"location\": null,\n" + " \"type\": \"%s\"\n" + "}";
byte[] b = format(json, importType).getBytes(Charset.defaultCharset());
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/import/new_project", "http://localhost:8080/api", headers, b, null);
assertEquals(response.getStatus(), 204);
RegisteredProject newProject = pm.getProject("new_project");
assertNotNull(newProject);
//assertNotNull(newProject.getConfig());
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class WorkspaceService method updateProject.
@PUT
@Path("/{id}/project/{path:.*}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace project by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The project successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the project"), @ApiResponse(code = 404, message = "The workspace or the project not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateProject(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The path to the project") @PathParam("path") String path, @ApiParam(value = "The project update", required = true) ProjectConfigDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Project config");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<ProjectConfigImpl> projects = workspace.getConfig().getProjects();
final String normalizedPath = path.startsWith("/") ? path : '/' + path;
if (!projects.removeIf(project -> project.getPath().equals(normalizedPath))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain project with path '%s'", id, normalizedPath));
}
projects.add(new ProjectConfigImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
Aggregations