Java Code Examples for org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#setId()

The following examples show how to use org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkspaceDaoTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
public static WorkspaceImpl createWorkspaceFromConfig(
    String id, AccountImpl account, String name) {
  final WorkspaceConfigImpl wCfg = createWorkspaceConfig(name);
  // Workspace
  final WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId(id);
  workspace.setAccount(account);
  wCfg.setName(name);
  workspace.setConfig(wCfg);
  workspace.setAttributes(
      new HashMap<>(
          ImmutableMap.of(
              "attr1", "value1",
              "attr2", "value2",
              "attr3", "value3")));
  workspace.setConfig(wCfg);
  return workspace;
}
 
Example 2
Source File: WorkspaceDaoTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
public static WorkspaceImpl createWorkspaceFromDevfile(
    String id, AccountImpl account, String name) {
  final DevfileImpl devfile = createDevfile(name);
  // Workspace
  final WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId(id);
  workspace.setAccount(account);
  workspace.setDevfile(devfile);
  workspace.setAttributes(
      new HashMap<>(
          ImmutableMap.of(
              "attr1", "value1",
              "attr2", "value2",
              "attr3", "value3")));
  return workspace;
}
 
Example 3
Source File: WorkspaceRuntimesTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldNotInjectRuntimeIfExceptionOccurredOnRuntimeFetching() 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);
  ImmutableMap<String, Machine> machines =
      ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
  when(context.getRuntime())
      .thenReturn(new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING));
  doThrow(new InfrastructureException("error")).when(infrastructure).prepare(eq(identity), any());

  // when
  WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId("workspace123");
  runtimes.injectRuntime(workspace);

  // then
  assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
  assertNull(workspace.getRuntime());
}
 
Example 4
Source File: WorkspaceActivityDaoTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private static WorkspaceImpl createWorkspace(String id, AccountImpl account, String name) {
  final WorkspaceConfigImpl wCfg = createWorkspaceConfig(name);
  // Workspace
  final WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId(id);
  workspace.setAccount(account);
  wCfg.setName(name);
  workspace.setConfig(wCfg);
  return workspace;
}
 
Example 5
Source File: WorkspaceDaoTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test(expectedExceptions = NotFoundException.class)
public void shouldNotUpdateWorkspaceWhichDoesNotExist() throws Exception {
  final WorkspaceImpl workspace = workspaces[0];
  workspace.setId("non-existing-workspace");

  workspaceDao.update(workspace);
}
 
Example 6
Source File: WorkspaceRuntimesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldInjectRuntime() throws Exception {
  // given
  WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId("ws123");
  when(statuses.get("ws123")).thenReturn(WorkspaceStatus.RUNNING);

  ImmutableMap<String, Machine> machines =
      ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));

  RuntimeIdentity identity = new RuntimeIdentityImpl("ws123", "my-env", "myId", "infraNamespace");
  RuntimeContext context = mockContext(identity);
  doReturn(context).when(infrastructure).prepare(eq(identity), any());

  ConcurrentHashMap<String, InternalRuntime<?>> runtimesStorage = new ConcurrentHashMap<>();
  TestInternalRuntime testRuntime =
      new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
  runtimesStorage.put("ws123", testRuntime);
  WorkspaceRuntimes localRuntimes =
      new WorkspaceRuntimes(
          runtimesStorage,
          eventService,
          ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory),
          infrastructure,
          sharedPool,
          workspaceDao,
          dbInitializer,
          probeScheduler,
          statuses,
          lockService,
          devfileConverter);

  // when
  localRuntimes.injectRuntime(workspace);

  // then
  assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
  assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
 
Example 7
Source File: WorkspaceRuntimesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@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));
}
 
Example 8
Source File: WorkspaceRuntimesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldNotInjectRuntimeIfThereIsNoCachedStatus() throws Exception {
  // when
  WorkspaceImpl workspace = new WorkspaceImpl();
  workspace.setId("workspace123");
  runtimes.injectRuntime(workspace);

  // then
  assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
  assertNull(workspace.getRuntime());
}