use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceServiceTest method shouldAddEnvironment.
@Test
public void shouldAddEnvironment() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
final EnvironmentDto envDto = createEnvDto();
final int envsSizeBefore = workspace.getConfig().getEnvironments().size();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(envDto).when().queryParam("name", "new-env").post(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment");
assertEquals(response.getStatusCode(), 200);
assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT).getConfig().getEnvironments().size(), envsSizeBefore + 1);
verify(validator).validateConfig(workspace.getConfig());
verify(wsManager).updateWorkspace(any(), any());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceServiceTest method shouldDeleteEnvironment.
@Test
public void shouldDeleteEnvironment() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
Map.Entry<String, EnvironmentImpl> envEntry = workspace.getConfig().getEnvironments().entrySet().iterator().next();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().delete(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment/" + envEntry.getKey());
assertEquals(response.getStatusCode(), 204);
verify(wsManager).updateWorkspace(any(), any());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceServiceTest method shouldUpdateTheWorkspace.
@Test
public void shouldUpdateTheWorkspace() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.updateWorkspace(any(), any())).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).when().put(SECURE_PATH + "/workspace/" + workspace.getId());
assertEquals(response.getStatusCode(), 200);
assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
verify(validator).validateWorkspace(any());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class FactoryService method getFactoryJson.
@GET
@Path("/workspace/{ws-id}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Construct factory from workspace", notes = "This call returns a Factory.json that is used to create a factory")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains requested factory JSON"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 404, message = "Workspace not found"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getFactoryJson(@ApiParam(value = "Workspace identifier") @PathParam("ws-id") String wsId, @ApiParam(value = "Project path") @QueryParam("path") String path) throws BadRequestException, NotFoundException, ServerException {
final WorkspaceImpl workspace = workspaceManager.getWorkspace(wsId);
excludeProjectsWithoutLocation(workspace, path);
final FactoryDto factoryDto = DtoFactory.newDto(FactoryDto.class).withV("4.0").withWorkspace(org.eclipse.che.api.workspace.server.DtoConverter.asDto(workspace.getConfig()));
return Response.ok(factoryDto, APPLICATION_JSON).header(CONTENT_DISPOSITION, "attachment; filename=factory.json").build();
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceManager method stopWorkspace.
/**
* Asynchronously stops the workspace,
* creates a snapshot of it if {@code createSnapshot} is set to true.
*
* @param workspaceId
* the id of the workspace to stop
* @param createSnapshot
* true if create snapshot, false if don't,
* null if default behaviour should be used
* @throws ServerException
* when any server error occurs
* @throws NullPointerException
* when {@code workspaceId} is null
* @throws NotFoundException
* when workspace {@code workspaceId} doesn't have runtime
*/
public void stopWorkspace(String workspaceId, @Nullable Boolean createSnapshot) throws ConflictException, NotFoundException, ServerException {
requireNonNull(workspaceId, "Required non-null workspace id");
final WorkspaceImpl workspace = workspaceDao.get(workspaceId);
workspace.setStatus(runtimes.getStatus(workspaceId));
if (workspace.getStatus() != WorkspaceStatus.RUNNING && workspace.getStatus() != WorkspaceStatus.STARTING) {
throw new ConflictException(format("Could not stop the workspace '%s/%s' because its status is '%s'. " + "Workspace must be either 'STARTING' or 'RUNNING'", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getStatus()));
}
stopAsync(workspace, createSnapshot);
}
Aggregations