use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class DtoConverter method asDto.
/** Converts {@link ProjectConfig} to {@link ProjectConfigDto}. */
public static ProjectConfigDto asDto(ProjectConfig projectCfg) {
final ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName(projectCfg.getName()).withDescription(projectCfg.getDescription()).withPath(projectCfg.getPath()).withType(projectCfg.getType()).withAttributes(projectCfg.getAttributes()).withMixins(projectCfg.getMixins());
final SourceStorage source = projectCfg.getSource();
if (source != null) {
projectConfigDto.withSource(newDto(SourceStorageDto.class).withLocation(source.getLocation()).withType(source.getType()).withParameters(source.getParameters()));
}
return projectConfigDto;
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class MavenProjectTypeTest method testMavenProject.
@Test
public void testMavenProject() throws Exception {
WorkspaceDto usersWorkspaceMock = mock(WorkspaceDto.class);
WorkspaceConfigDto workspaceConfigMock = mock(WorkspaceConfigDto.class);
when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class).withMethod("GET").withHref("/workspace/")))).thenReturn(httpJsonRequest);
when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class).withMethod("PUT").withHref("/workspace/" + "/project")))).thenReturn(httpJsonRequest);
when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
final ProjectConfigDto projectConfig = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withName("project").withPath("/myProject").withType(MavenAttributes.MAVEN_ID);
when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
when(workspaceConfigMock.getProjects()).thenReturn(Collections.singletonList(projectConfig));
Map<String, List<String>> attributes = new HashMap<>();
attributes.put(MavenAttributes.ARTIFACT_ID, Collections.singletonList("myartifact"));
attributes.put(MavenAttributes.GROUP_ID, Collections.singletonList("mygroup"));
attributes.put(MavenAttributes.VERSION, Collections.singletonList("1.0"));
attributes.put(MavenAttributes.PACKAGING, Collections.singletonList("jar"));
RegisteredProject project = pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType("maven").withAttributes(attributes).withPath("/myProject").withName("myProject"), new HashMap<>(0));
for (VirtualFileEntry file : project.getBaseFolder().getChildren()) {
if (file.getName().equals("pom.xml")) {
Model pom = Model.readFrom(file.getVirtualFile().getContent());
Assert.assertEquals(pom.getVersion(), "1.0");
}
}
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class SimpleGeneratorStrategyTest method prepareProject.
private void prepareProject() throws Exception {
final String vfsUser = "dev";
Set<ProjectTypeDef> pts = new HashSet<>();
final ProjectTypeDef pt = new ProjectTypeDef("mytype", "mytype type", true, false) {
};
pts.add(pt);
final ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(pts);
final EventService eventService = new EventService();
// final VirtualFileSystemRegistry vfsRegistry = new VirtualFileSystemRegistry();
// final MemoryFileSystemProvider memoryFileSystemProvider =
// new MemoryFileSystemProvider(workspace,
// eventService,
// new VirtualFileSystemUserContext() {
// @Override
// public VirtualFileSystemUser getVirtualFileSystemUser() {
// return new VirtualFileSystemUser(vfsUser, vfsUserGroups);
// }
// },
// vfsRegistry,
// SystemPathsFilter.ANY);
// vfsRegistry.registerProvider(workspace, memoryFileSystemProvider);
WorkspaceDto usersWorkspaceMock = mock(WorkspaceDto.class);
final ProjectConfigDto projectConfigDto = DtoFactory.getInstance().createDto(ProjectConfigDto.class).withPath("/my_project");
WorkspaceConfigDto workspaceConfigMock = mock(WorkspaceConfigDto.class);
when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
when(workspaceConfigMock.getProjects()).thenReturn(Collections.singletonList(projectConfigDto));
ProjectHandlerRegistry handlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
// pm = new ProjectManager(vfsRegistry,
// eventService,
// projectTypeRegistry,
// handlerRegistry,
// filterProvider,
// API_ENDPOINT,
// httpJsonRequestFactory);
// HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
// when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class)
// .withMethod("PUT")
// .withHref(API_ENDPOINT + "/workspace/" + workspace + "/project"))))
// .thenReturn(httpJsonRequest);
// when(httpJsonRequestFactory.fromLink(eq(DtoFactory.newDto(Link.class)
// .withMethod("GET")
// .withHref(API_ENDPOINT + "/workspace/" + workspace))))
// .thenReturn(httpJsonRequest);
// when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
pm.createProject(DtoFactory.getInstance().createDto(ProjectConfigDto.class).withType(pt.getId()).withName("my_project").withPath("/my_project"), null);
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class MavenModelImporter method onFactoryAccepted.
@Override
public void onFactoryAccepted(FactoryAcceptedEvent event) {
final FactoryDto factory = event.getFactory();
final List<ProjectConfigDto> projects = factory.getWorkspace().getProjects();
final List<String> paths = new ArrayList<>();
for (ProjectConfigDto project : projects) {
if (MavenAttributes.MAVEN_ID.equals(project.getType())) {
paths.add(project.getPath());
}
}
if (!paths.isEmpty()) {
reimport(paths);
}
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class WorkspaceServiceTest method shouldAddProject.
@Test
public void shouldAddProject() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
final ProjectConfigDto projectDto = createProjectDto();
final int projectsSizeBefore = workspace.getConfig().getProjects().size();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(projectDto).when().post(SECURE_PATH + "/workspace/" + workspace.getId() + "/project");
assertEquals(response.getStatusCode(), 200);
assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT).getConfig().getProjects().size(), projectsSizeBefore + 1);
verify(validator).validateConfig(workspace.getConfig());
verify(wsManager).updateWorkspace(any(), any());
}
Aggregations