Search in sources :

Example 1 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class FactoryServiceTest method shouldGenerateFactoryJsonIncludeGivenProjects.

@Test
public void shouldGenerateFactoryJsonIncludeGivenProjects() throws Exception {
    // given
    final String wsId = "workspace123234";
    WorkspaceImpl.WorkspaceImplBuilder ws = WorkspaceImpl.builder();
    WorkspaceConfigImpl.WorkspaceConfigImplBuilder wsConfig = WorkspaceConfigImpl.builder();
    ws.setId(wsId);
    wsConfig.setProjects(Arrays.asList(DTO.createDto(ProjectConfigDto.class).withPath("/proj1").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location")), DTO.createDto(ProjectConfigDto.class).withPath("/proj2").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location"))));
    wsConfig.setName("wsname");
    wsConfig.setEnvironments(singletonMap("env1", DTO.createDto(EnvironmentDto.class)));
    wsConfig.setDefaultEnv("env1");
    ws.setStatus(WorkspaceStatus.RUNNING);
    wsConfig.setCommands(singletonList(DTO.createDto(CommandDto.class).withName("MCI").withType("mvn").withCommandLine("clean install")));
    ws.setConfig(wsConfig.build());
    WorkspaceImpl usersWorkspace = ws.build();
    when(workspaceManager.getWorkspace(eq(wsId))).thenReturn(usersWorkspace);
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get("/private" + SERVICE_PATH + "/workspace/" + wsId);
    // then
    assertEquals(response.getStatusCode(), 200);
    FactoryDto result = DTO.createDtoFromJson(response.getBody().asString(), FactoryDto.class);
    assertEquals(result.getWorkspace().getProjects().size(), 2);
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 2 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceManagerTest method shouldBeAbleToUpdateWorkspace.

@Test
public void shouldBeAbleToUpdateWorkspace() throws Exception {
    WorkspaceImpl workspace = new WorkspaceImpl(createAndMockWorkspace());
    workspace.setTemporary(true);
    workspace.getAttributes().put("new attribute", "attribute");
    when(workspaceDao.update(any())).thenAnswer(inv -> inv.getArguments()[0]);
    workspaceManager.updateWorkspace(workspace.getId(), workspace);
    verify(workspaceDao).update(workspace);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 3 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceManagerTest method snapshottedAtAttributeIncludedToWorkspaceWhenGettingByNamespaceAndName.

@Test
public void snapshottedAtAttributeIncludedToWorkspaceWhenGettingByNamespaceAndName() throws Exception {
    WorkspaceImpl workspace = createAndMockWorkspace();
    mockSnapshots(workspace, 12345);
    WorkspaceImpl result = workspaceManager.getWorkspace(workspace.getConfig().getName(), workspace.getNamespace());
    assertEquals(result.getAttributes().get(SNAPSHOTTED_AT_ATTRIBUTE_NAME), "12345");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 4 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method interruptsStartAfterEnvironmentIsStartedButRuntimeStatusIsNotRunning.

@Test
public void interruptsStartAfterEnvironmentIsStartedButRuntimeStatusIsNotRunning() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    // let's say status is changed to STOPPING by stop method,
    // but starting thread hasn't been interrupted yet
    allowEnvironmentStart(workspace, "env-name", () -> setRuntime("workspace", WorkspaceStatus.STOPPING));
    CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
    captureAndVerifyRuntimeStateAfterInterruption(workspace, cmpFuture);
    verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.STOPPED, null));
    verify(envEngine).stop(workspace.getId());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 5 with WorkspaceImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.

the class WorkspaceRuntimesTest method interruptsStartAfterEnvironmentIsStartedButThreadIsInterrupted.

@Test
public void interruptsStartAfterEnvironmentIsStartedButThreadIsInterrupted() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    // the status is successfully updated from STARTING -> RUNNING but after
    // that thread is interrupted so #stop is waiting for starting thread to stop the environment
    allowEnvironmentStart(workspace, "env-name", () -> Thread.currentThread().interrupt());
    CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
    captureAndVerifyRuntimeStateAfterInterruption(workspace, cmpFuture);
    verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.STOPPED, null));
    verify(envEngine).stop(workspace.getId());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Aggregations

WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)165 Test (org.testng.annotations.Test)130 Response (com.jayway.restassured.response.Response)34 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)15 ServerException (org.eclipse.che.api.core.ServerException)14 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)12 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 AccountImpl (org.eclipse.che.account.spi.AccountImpl)11 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)9 NotFoundException (org.eclipse.che.api.core.NotFoundException)8 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)8 Consumes (javax.ws.rs.Consumes)7 ConflictException (org.eclipse.che.api.core.ConflictException)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7