Search in sources :

Example 6 with RuntimeDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeDto in project devspaces-images by redhat-developer.

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue.

@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasNoValue() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    String internalServerKey = "server1";
    ServerImpl externalServer = createExternalServer();
    ServerImpl internalServer = createInternalServer();
    Map<String, Server> servers = ImmutableMap.of(internalServerKey, createInternalServer(), externalServerKey, externalServer);
    Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
    workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(ImmutableMap.of(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()), internalServerKey, newDto(ServerDto.class).withUrl(createInternalServer().getUrl()).withStatus(internalServer.getStatus()).withAttributes(internalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).queryParam("includeInternalServers").when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
    assertNotNull(retrievedRuntime);
    assertEquals(expected, retrievedRuntime.getMachines());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Response(io.restassured.response.Response) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto) Test(org.testng.annotations.Test)

Example 7 with RuntimeDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeDto in project devspaces-images by redhat-developer.

the class WorkspaceServiceTest method shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal.

@Test
public void shouldTreatServerWithInternalServerAttributeNotEqualToTrueExternal() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    ServerImpl externalServer = createInternalServer().withAttributes(singletonMap(ServerConfig.INTERNAL_SERVER_ATTRIBUTE, ""));
    Map<String, Server> servers = ImmutableMap.of("server1", createInternalServer(), externalServerKey, externalServer);
    Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
    workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(singletonMap(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
    assertNotNull(retrievedRuntime);
    assertEquals(expected, retrievedRuntime.getMachines());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Response(io.restassured.response.Response) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto) Test(org.testng.annotations.Test)

Example 8 with RuntimeDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeDto in project devspaces-images by redhat-developer.

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue.

@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    String internalServerKey = "server1";
    ServerImpl externalServer = createExternalServer();
    ServerImpl internalServer = createInternalServer();
    Map<String, Server> servers = ImmutableMap.of(internalServerKey, createInternalServer(), externalServerKey, externalServer);
    Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
    workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(ImmutableMap.of(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()), internalServerKey, newDto(ServerDto.class).withUrl(createInternalServer().getUrl()).withStatus(internalServer.getStatus()).withAttributes(internalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).queryParam("includeInternalServers", "").when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
    assertNotNull(retrievedRuntime);
    assertEquals(expected, retrievedRuntime.getMachines());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Response(io.restassured.response.Response) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto) Test(org.testng.annotations.Test)

Example 9 with RuntimeDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeDto in project devspaces-images by redhat-developer.

the class DtoConverter method asDto.

/**
 * Converts {@link Workspace} to {@link WorkspaceDto}.
 */
public static WorkspaceDto asDto(Workspace workspace) {
    WorkspaceDto workspaceDto = newDto(WorkspaceDto.class).withId(workspace.getId()).withStatus(workspace.getStatus()).withNamespace(workspace.getNamespace()).withTemporary(workspace.isTemporary()).withAttributes(workspace.getAttributes());
    if (workspace.getConfig() != null) {
        workspaceDto.setConfig(asDto(workspace.getConfig()));
    }
    if (workspace.getDevfile() != null) {
        workspaceDto.setDevfile(asDto(workspace.getDevfile()));
    }
    if (workspace.getRuntime() != null) {
        RuntimeDto runtime = asDto(workspace.getRuntime());
        workspaceDto.setRuntime(runtime);
    }
    return workspaceDto;
}
Also used : WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto)

Example 10 with RuntimeDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeDto in project che-server by eclipse-che.

the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue.

@Test
public void shouldGetWorkspaceWithInternalServersIfCorrespondingQueryParamHasEmptyValue() throws Exception {
    // given
    WorkspaceImpl workspace = createWorkspace(createConfigDto());
    String externalServerKey = "server2";
    String internalServerKey = "server1";
    ServerImpl externalServer = createExternalServer();
    ServerImpl internalServer = createInternalServer();
    Map<String, Server> servers = ImmutableMap.of(internalServerKey, createInternalServer(), externalServerKey, externalServer);
    Map<String, Machine> machines = singletonMap("machine1", new MachineImpl(singletonMap("key", "value"), servers, RUNNING));
    workspace.setRuntime(new RuntimeImpl("activeEnv", machines, "user123"));
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    Map<String, MachineDto> expected = singletonMap("machine1", newDto(MachineDto.class).withAttributes(singletonMap("key", "value")).withStatus(RUNNING).withServers(ImmutableMap.of(externalServerKey, newDto(ServerDto.class).withUrl(externalServer.getUrl()).withStatus(externalServer.getStatus()).withAttributes(externalServer.getAttributes()), internalServerKey, newDto(ServerDto.class).withUrl(createInternalServer().getUrl()).withStatus(internalServer.getStatus()).withAttributes(internalServer.getAttributes()))));
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).queryParam("includeInternalServers", "").when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    RuntimeDto retrievedRuntime = unwrapDto(response, WorkspaceDto.class).getRuntime();
    assertNotNull(retrievedRuntime);
    assertEquals(expected, retrievedRuntime.getMachines());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) Server(org.eclipse.che.api.core.model.workspace.runtime.Server) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Machine(org.eclipse.che.api.core.model.workspace.runtime.Machine) Response(io.restassured.response.Response) MachineDto(org.eclipse.che.api.workspace.shared.dto.MachineDto) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) RuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl) RuntimeDto(org.eclipse.che.api.workspace.shared.dto.RuntimeDto) Test(org.testng.annotations.Test)

Aggregations

RuntimeDto (org.eclipse.che.api.workspace.shared.dto.RuntimeDto)14 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)14 Response (io.restassured.response.Response)10 Machine (org.eclipse.che.api.core.model.workspace.runtime.Machine)10 Server (org.eclipse.che.api.core.model.workspace.runtime.Server)10 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)10 RuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl)10 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)10 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)10 MachineDto (org.eclipse.che.api.workspace.shared.dto.MachineDto)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Test (org.testng.annotations.Test)10 ServerException (org.eclipse.che.api.core.ServerException)2 MachineAccessForbidden (org.eclipse.che.api.workspace.server.token.MachineAccessForbidden)2 MachineTokenException (org.eclipse.che.api.workspace.server.token.MachineTokenException)2