Search in sources :

Example 56 with WorkspaceImpl

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

the class WorkspaceManagerTest method snapshottedAtAttributeIncludedToWorkspaceWhenStartingById.

@Test
public void snapshottedAtAttributeIncludedToWorkspaceWhenStartingById() throws Exception {
    WorkspaceImpl workspace = createAndMockWorkspace();
    mockSnapshots(workspace, 12345);
    mockStart(workspace);
    Workspace result = workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
    assertEquals(result.getAttributes().get(SNAPSHOTTED_AT_ATTRIBUTE_NAME), "12345");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) Test(org.testng.annotations.Test)

Example 57 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldGetWorkspaces.

@Test
public void shouldGetWorkspaces() throws Exception {
    final WorkspaceImpl workspace1 = createWorkspace(createConfigDto());
    final WorkspaceImpl workspace2 = createWorkspace(createConfigDto(), STARTING);
    when(wsManager.getWorkspaces(USER_ID, false)).thenReturn(asList(workspace1, workspace2));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(unwrapDtoList(response, WorkspaceDto.class).stream().map(ws -> new WorkspaceImpl(ws, TEST_ACCOUNT)).collect(toList()), asList(workspace1, workspace2));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 58 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldUseUsernameAsNamespaceWhenStartingWorkspaceFromConfigWithoutNamespace.

@Test
public void shouldUseUsernameAsNamespaceWhenStartingWorkspaceFromConfigWithoutNamespace() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.startWorkspace(anyObject(), anyString(), anyBoolean())).thenReturn(workspace);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    final WorkspaceDto workspaceDto = DtoConverter.asDto(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(workspaceDto.getConfig()).when().post(SECURE_PATH + "/workspace/runtime" + "?temporary=true");
    assertEquals(response.getStatusCode(), 200);
    verify(validator).validateConfig(any());
    verify(wsManager).startWorkspace(any(), eq(NAMESPACE), eq(true));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Test(org.testng.annotations.Test)

Example 59 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldCreateWorkspace.

@Test
public void shouldCreateWorkspace() throws Exception {
    final WorkspaceConfigDto configDto = createConfigDto();
    final WorkspaceImpl workspace = createWorkspace(configDto);
    when(wsManager.createWorkspace(any(), any(), any())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(configDto).when().post(SECURE_PATH + "/workspace" + "?namespace=test" + "&attribute=stackId:stack123" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(validator).validateConfig(any());
    verify(validator).validateAttributes(any());
    verify(wsManager).createWorkspace(anyObject(), eq("test"), eq(ImmutableMap.of("stackId", "stack123", "factoryId", "factory123", "custom", "custom:value")));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) Test(org.testng.annotations.Test)

Example 60 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldRespond404WhenUpdatingEnvironmentWhichDoesNotExist.

@Test
public void shouldRespond404WhenUpdatingEnvironmentWhichDoesNotExist() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(createEnvDto()).when().put(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment/fake");
    assertEquals(response.getStatusCode(), 404);
    assertEquals(unwrapError(response), "Workspace '" + workspace.getId() + "' doesn't contain environment 'fake'");
    verify(wsManager, never()).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) 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