Search in sources :

Example 1 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto 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 2 with StackDto

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

the class StackServiceTest method newStackShouldBeCreatedForUser.

/** Create stack */
@Test
public void newStackShouldBeCreatedForUser() throws ConflictException, ServerException {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(stackDto).when().post(SECURE_PATH + "/stack");
    assertEquals(response.getStatusCode(), 201);
    verify(stackDao).create(any(StackImpl.class));
    final StackDto stackDtoDescriptor = unwrapDto(response, StackDto.class);
    assertEquals(stackDtoDescriptor.getName(), stackDto.getName());
    assertEquals(stackDtoDescriptor.getCreator(), USER_ID);
    assertEquals(stackDtoDescriptor.getDescription(), stackDto.getDescription());
    assertEquals(stackDtoDescriptor.getTags(), stackDto.getTags());
    assertEquals(stackDtoDescriptor.getComponents(), stackDto.getComponents());
    assertEquals(stackDtoDescriptor.getSource(), stackDto.getSource());
    assertEquals(stackDtoDescriptor.getScope(), stackDto.getScope());
    assertEquals(stackDtoDescriptor.getLinks().size(), 2);
    assertEquals(stackDtoDescriptor.getLinks().get(0).getRel(), LINK_REL_REMOVE_STACK);
    assertEquals(stackDtoDescriptor.getLinks().get(1).getRel(), LINK_REL_GET_STACK_BY_ID);
}
Also used : Response(com.jayway.restassured.response.Response) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Test(org.testng.annotations.Test)

Example 3 with StackDto

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

the class StackServiceTest method shouldReturnsAllStacksWhenListTagsIsEmpty.

/** Search stack by tags */
@Test
public void shouldReturnsAllStacksWhenListTagsIsEmpty() throws ServerException {
    StackImpl stack2 = new StackImpl(stackImpl);
    stack2.setTags(singletonList("subversion"));
    List<StackImpl> stacks = asList(stackImpl, stack2);
    when(stackDao.searchStacks(anyString(), anyList(), anyInt(), anyInt())).thenReturn(stacks);
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/stack");
    assertEquals(response.getStatusCode(), 200);
    verify(stackDao).searchStacks(anyString(), anyList(), anyInt(), anyInt());
    List<StackDto> result = unwrapListDto(response, StackDto.class);
    assertEquals(result.size(), 2);
    assertEquals(result.get(0).getName(), stackImpl.getName());
    assertEquals(result.get(1).getName(), stack2.getName());
}
Also used : Response(com.jayway.restassured.response.Response) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Test(org.testng.annotations.Test)

Example 4 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto 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 5 with StackDto

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

the class StackServiceTest method creatorShouldNotBeUpdated.

@Test
public void creatorShouldNotBeUpdated() throws ServerException, NotFoundException, ConflictException {
    StackDto updatedStackDto = DtoFactory.getInstance().createDto(StackDto.class).withId(STACK_ID).withName(NAME).withDescription(DESCRIPTION).withScope(SCOPE).withCreator("creator changed").withTags(tags).withSource(stackSourceDto).withComponents(componentsDto);
    when(stackDao.getById(anyString())).thenReturn(foreignStack);
    when(stackDao.update(any())).thenReturn(foreignStack);
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).content(updatedStackDto).when().put(SECURE_PATH + "/stack/" + STACK_ID);
    assertEquals(response.getStatusCode(), 200);
    StackDto result = unwrapDto(response, StackDto.class);
    assertEquals(result.getId(), updatedStackDto.getId());
    assertEquals(result.getName(), updatedStackDto.getName());
    assertEquals(result.getDescription(), updatedStackDto.getDescription());
    assertEquals(result.getScope(), updatedStackDto.getScope());
    assertEquals(result.getTags().get(0), updatedStackDto.getTags().get(0));
    assertEquals(result.getTags().get(1), updatedStackDto.getTags().get(1));
    assertEquals(result.getComponents().get(0).getName(), updatedStackDto.getComponents().get(0).getName());
    assertEquals(result.getComponents().get(0).getVersion(), updatedStackDto.getComponents().get(0).getVersion());
    assertEquals(result.getSource().getType(), updatedStackDto.getSource().getType());
    assertEquals(result.getSource().getOrigin(), updatedStackDto.getSource().getOrigin());
    assertEquals(result.getCreator(), FOREIGN_CREATOR);
    verify(stackDao).update(any());
    verify(stackDao).getById(STACK_ID);
}
Also used : Response(com.jayway.restassured.response.Response) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Test(org.testng.annotations.Test)

Aggregations

StackDto (org.eclipse.che.api.workspace.shared.dto.stack.StackDto)9 Test (org.testng.annotations.Test)7 Response (com.jayway.restassured.response.Response)6 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)4 StackComponentDto (org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto)3 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)2 StackSourceDto (org.eclipse.che.api.workspace.shared.dto.stack.StackSourceDto)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)1 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)1 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)1 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)1 StackComponentImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl)1 StackSourceImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl)1 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)1