Search in sources :

Example 11 with WorkspaceConfigDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto in project che by eclipse.

the class WorkspaceServiceTest method shouldCreateWorkspace.

@Test
public void shouldCreateWorkspace() throws Exception {
    final WorkspaceConfigDto configDto = createConfigDto();
    final WorkspaceImpl workspace = createWorkspace(configDto);
    when(wsManager.createWorkspace(any(), any(), any())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(configDto).when().post(SECURE_PATH + "/workspace" + "?namespace=test" + "&attribute=stackId:stack123" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(validator).validateConfig(any());
    verify(validator).validateAttributes(any());
    verify(wsManager).createWorkspace(anyObject(), eq("test"), eq(ImmutableMap.of("stackId", "stack123", "factoryId", "factory123", "custom", "custom:value")));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Test(org.testng.annotations.Test)

Example 12 with WorkspaceConfigDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto in project che by eclipse.

the class WorkspaceServiceTest method shouldUseUsernameAsNamespaceWhenCreatingWorkspaceWithoutSpecifiedNamespace.

@Test
public void shouldUseUsernameAsNamespaceWhenCreatingWorkspaceWithoutSpecifiedNamespace() throws Exception {
    final WorkspaceConfigDto configDto = createConfigDto();
    final WorkspaceImpl workspace = createWorkspace(configDto);
    when(wsManager.createWorkspace(any(), any(), any())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(configDto).when().post(SECURE_PATH + "/workspace" + "?attribute=stackId:stack123" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(validator).validateConfig(any());
    verify(validator).validateAttributes(any());
    verify(wsManager).createWorkspace(anyObject(), eq(NAMESPACE), eq(ImmutableMap.of("stackId", "stack123", "factoryId", "factory123", "custom", "custom:value")));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Test(org.testng.annotations.Test)

Example 13 with WorkspaceConfigDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto in project che by eclipse.

the class DtoConverter method asDto.

/** Convert {@link StackImpl} to {@link StackDto}. */
public static StackDto asDto(Stack stack) {
    WorkspaceConfigDto workspaceConfigDto = null;
    if (stack.getWorkspaceConfig() != null) {
        workspaceConfigDto = asDto(stack.getWorkspaceConfig());
    }
    StackSourceDto stackSourceDto = null;
    StackSource source = stack.getSource();
    if (source != null) {
        stackSourceDto = newDto(StackSourceDto.class).withType(source.getType()).withOrigin(source.getOrigin());
    }
    List<StackComponentDto> componentsDto = null;
    if (stack.getComponents() != null) {
        componentsDto = stack.getComponents().stream().map(component -> newDto(StackComponentDto.class).withName(component.getName()).withVersion(component.getVersion())).collect(toList());
    }
    return newDto(StackDto.class).withId(stack.getId()).withName(stack.getName()).withDescription(stack.getDescription()).withCreator(stack.getCreator()).withScope(stack.getScope()).withTags(stack.getTags()).withComponents(componentsDto).withWorkspaceConfig(workspaceConfigDto).withSource(stackSourceDto);
}
Also used : StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) StackSourceDto(org.eclipse.che.api.workspace.shared.dto.stack.StackSourceDto) StackSource(org.eclipse.che.api.workspace.shared.stack.StackSource)

Example 14 with WorkspaceConfigDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto in project che by eclipse.

the class StackLoaderTest method dtoShouldBeSerialized.

@Test
public void dtoShouldBeSerialized() {
    StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
    StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
    stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
    stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
    stackDtoDescriptor.setDescription("description");
    stackDtoDescriptor.setId("someId");
    stackDtoDescriptor.setScope("scope");
    stackDtoDescriptor.setCreator("Created in Codenvy");
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute1", "valute attribute1");
    Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
    HashMap<String, List<String>> projectMap = new HashMap<>();
    projectMap.put("test", Arrays.asList("test", "test2"));
    ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
    SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
    ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
    EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
    Map<String, ServerConf2Dto> servers = new HashMap<>();
    servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
    Map<String, ExtendedMachineDto> machines = new HashMap<>();
    machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
    EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
    CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
    WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
    stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
    Gson GSON = new GsonBuilder().create();
    GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
Also used : HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) Gson(com.google.gson.Gson) ServerConf2Dto(org.eclipse.che.api.workspace.shared.dto.ServerConf2Dto) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) List(java.util.List) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Link(org.eclipse.che.api.core.rest.shared.dto.Link) ProjectProblemDto(org.eclipse.che.api.workspace.shared.dto.ProjectProblemDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Test(org.testng.annotations.Test)

Example 15 with WorkspaceConfigDto

use of org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto in project che by eclipse.

the class CreateWorkspacePresenter method getWorkspaceConfig.

private WorkspaceConfigDto getWorkspaceConfig() {
    String wsName = view.getWorkspaceName();
    EnvironmentRecipeDto recipe = dtoFactory.createDto(EnvironmentRecipeDto.class).withType("dockerimage").withLocation(view.getRecipeUrl());
    ExtendedMachineDto machine = dtoFactory.createDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withAttributes(singletonMap("memoryLimitBytes", MEMORY_LIMIT_BYTES));
    EnvironmentDto environment = dtoFactory.createDto(EnvironmentDto.class).withRecipe(recipe).withMachines(singletonMap(WS_MACHINE_NAME, machine));
    return dtoFactory.createDto(WorkspaceConfigDto.class).withName(wsName).withDefaultEnv(wsName).withEnvironments(singletonMap(wsName, environment));
}
Also used : EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)

Aggregations

WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)29 Test (org.testng.annotations.Test)17 EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)8 HashMap (java.util.HashMap)6 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)6 Test (org.junit.Test)5 ExtendedMachineDto (org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Response (com.jayway.restassured.response.Response)3 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)3 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)3 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)3 EnvironmentRecipeDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)3 WorkspaceRuntimeDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)2 StackComponentDto (org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto)2 StackDto (org.eclipse.che.api.workspace.shared.dto.stack.StackDto)2