use of org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithExternalServersByDefault.
@Test
public void shouldGetWorkspaceWithExternalServersByDefault() throws Exception {
// given
WorkspaceImpl workspace = createWorkspace(createConfigDto());
String externalServerKey = "server2";
ServerImpl externalServer = createExternalServer();
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());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl in project che-server by eclipse-che.
the class WorkspaceManagerTest method getsWorkspacesAvailableForUserWithRuntimes.
@Test
public void getsWorkspacesAvailableForUserWithRuntimes() throws Exception {
final WorkspaceConfig config = createConfig();
final WorkspaceImpl workspace1 = createAndMockWorkspace(config, NAMESPACE_1);
final WorkspaceImpl workspace2 = createAndMockWorkspace(config, NAMESPACE_2);
final TestRuntime runtime2 = mockRuntime(workspace2, RUNNING);
when(workspaceDao.getWorkspaces(eq(NAMESPACE_1), anyInt(), anyLong())).thenReturn(new Page<>(asList(workspace1, workspace2), 0, 2, 2));
final Page<WorkspaceImpl> result = workspaceManager.getWorkspaces(NAMESPACE_1, true, 30, 0);
assertEquals(result.getItems().size(), 2);
final WorkspaceImpl res1 = result.getItems().get(0);
assertEquals(res1.getStatus(), STOPPED, "Workspace status wasn't changed from STARTING to STOPPED");
assertNull(res1.getRuntime(), "Workspace has unexpected runtime");
assertFalse(res1.isTemporary(), "Workspace must be permanent");
final WorkspaceImpl res2 = result.getItems().get(1);
assertEquals(res2.getStatus(), RUNNING, "Workspace status wasn't changed to the runtime instance status");
assertEquals(res2.getRuntime(), new RuntimeImpl(runtime2), "Workspace doesn't have expected runtime");
assertFalse(res2.isTemporary(), "Workspace must be permanent");
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl in project che-server by eclipse-che.
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());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldGetWorkspaceWithInternalServers.
@Test
public void shouldGetWorkspaceWithInternalServers() 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", Boolean.TRUE.toString()).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());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeImpl in project che-server by eclipse-che.
the class WorkspaceServiceTest method shouldUpdateWorkspaceWithRuntime.
@Test
public void shouldUpdateWorkspaceWithRuntime() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
MachineImpl machine = new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING);
RuntimeImpl runtime = new RuntimeImpl("myenv", singletonMap("machine1", machine), "owner");
workspace.setRuntime(runtime);
when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
// when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
final WorkspaceDto workspaceDto = asDto(workspace);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(workspaceDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId());
assertEquals(response.getStatusCode(), 200);
assertEquals(unwrapDto(response, WorkspaceDto.class).getRuntime(), asDto(runtime));
}
Aggregations