use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project che-server by eclipse-che.
the class InternalRuntimeTest method shouldNotRewriteURLsOfInternalServers.
@Test
public void shouldNotRewriteURLsOfInternalServers() throws Exception {
// given
ServerImpl internalServer = createServer(singletonMap(ServerConfig.INTERNAL_SERVER_ATTRIBUTE, "true"));
ServerImpl regularServer = createServer(RUNNING);
MachineImpl machineWithInternalServer = new MachineImpl(createAttributes(), ImmutableMap.of("server1", regularServer, "server2", internalServer), MachineStatus.RUNNING);
ImmutableMap<String, MachineImpl> internalMachines = ImmutableMap.of("m1", createMachine(), "m2", machineWithInternalServer);
ImmutableMap<String, MachineImpl> expected = ImmutableMap.of("m1", rewriteURLs(createMachine()), "m2", new MachineImpl(createAttributes(), ImmutableMap.of("server1", rewriteURL(regularServer), "server2", internalServer), MachineStatus.RUNNING));
setRunningRuntime();
doReturn(internalMachines).when(internalRuntime).getInternalMachines();
// when
Map<String, ? extends Machine> actual = internalRuntime.getMachines();
// then
assertEquals(actual, expected);
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
the class WorkspaceManagerTest method mockRuntime.
private TestRuntime mockRuntime(WorkspaceImpl workspace, WorkspaceStatus status) throws Exception {
MachineImpl machine1 = createMachine();
MachineImpl machine2 = createMachine();
Map<String, Machine> machines = new HashMap<>();
machines.put("machine1", machine1);
machines.put("machine2", machine2);
List<WarningImpl> warnings = new ArrayList<>();
warnings.add(new WarningImpl(103, "used default value"));
warnings.add(new WarningImpl(105, "specified configuration parameter is ignored"));
TestRuntime runtime = new TestRuntime(machines, workspace.getConfig().getCommands(), warnings);
lenient().doAnswer(inv -> {
workspace.setStatus(status);
workspace.setRuntime(new RuntimeImpl(runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner(), runtime.getCommands(), runtime.getWarnings()));
return null;
}).when(runtimes).injectRuntime(workspace);
lenient().when(runtimes.isAnyActive()).thenReturn(true);
return runtime;
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method shouldRecoverRuntimeWhenThereIsNotCachedOneDuringInjecting.
@Test
public void shouldRecoverRuntimeWhenThereIsNotCachedOneDuringInjecting() throws Exception {
// given
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
mockWorkspaceWithConfig(identity);
when(statuses.get("workspace123")).thenReturn(WorkspaceStatus.STARTING);
RuntimeContext context = mockContext(identity);
doReturn(context).when(infrastructure).prepare(eq(identity), any());
ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
TestInternalRuntime testRuntime = new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
when(context.getRuntime()).thenReturn(testRuntime);
doReturn(mock(InternalEnvironment.class)).when(testEnvFactory).create(any());
doReturn(ImmutableSet.of(identity)).when(infrastructure).getIdentities();
// when
WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId("workspace123");
runtimes.injectRuntime(workspace);
// then
assertEquals(workspace.getStatus(), WorkspaceStatus.STARTING);
assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
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));
}
use of org.eclipse.che.api.workspace.server.model.impl.MachineImpl in project devspaces-images by redhat-developer.
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());
}
Aggregations