Search in sources :

Example 16 with WorkspaceImpl

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

the class WorkspaceRuntimesTest method cancellationOfPendingStartTask.

@Test
public void cancellationOfPendingStartTask() throws Throwable {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    when(sharedPool.submit(any())).thenReturn(Futures.immediateFuture(null));
    CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
    // the real start is not being executed, fake sharedPool suppressed it
    // so the situation is the same to the one if the task is cancelled before
    // executor service started executing it
    runtimes.stop(workspace.getId());
    // start awaiting clients MUST receive interruption
    try {
        cmpFuture.get();
    } catch (ExecutionException x) {
        verifyCompletionException(cmpFuture, EnvironmentStartInterruptedException.class, "Start of environment 'env-name' in workspace 'workspace' is interrupted");
    }
    // completed clients receive interrupted exception and cancellation doesn't bother them
    try {
        captureAsyncTaskAndExecuteSynchronously();
    } catch (CancellationException cancelled) {
        assertEquals(cancelled.getMessage(), "Start of the workspace 'workspace' was cancelled");
    }
    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));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CancellationException(java.util.concurrent.CancellationException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 17 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldNotRestoreWorkspace.

@Test
public void shouldNotRestoreWorkspace() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.startWorkspace(any(), any(), any())).thenReturn(workspace);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().post(SECURE_PATH + "/workspace/" + workspace.getId() + "/runtime" + "?environment=" + workspace.getConfig().getDefaultEnv() + "&restore=false");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(wsManager).startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 18 with WorkspaceImpl

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

the class WorkspaceServiceTest method shouldUpdateProject.

@Test
public void shouldUpdateProject() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final ProjectConfigDto projectDto = createProjectDto();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(projectDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId() + "/project" + projectDto.getPath());
    assertEquals(response.getStatusCode(), 200);
    verify(validator).validateConfig(workspace.getConfig());
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Test(org.testng.annotations.Test)

Example 19 with WorkspaceImpl

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

the class JpaWorkspaceDaoTest method shouldSynchronizeWorkspaceNameWithConfigNameWhenConfigIsUpdated.

@Test(expectedExceptions = DuplicateKeyException.class)
public void shouldSynchronizeWorkspaceNameWithConfigNameWhenConfigIsUpdated() throws Exception {
    final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
    final WorkspaceImpl workspace1 = createWorkspace("id", account, "name1");
    final WorkspaceImpl workspace2 = createWorkspace("id2", account, "name2");
    // persist prepared data
    manager.getTransaction().begin();
    manager.persist(account);
    manager.persist(workspace1);
    manager.persist(workspace2);
    manager.getTransaction().commit();
    // make conflict update
    workspace2.getConfig().setName(workspace1.getConfig().getName());
    manager.getTransaction().begin();
    manager.merge(workspace2);
    manager.getTransaction().commit();
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Test(org.testng.annotations.Test)

Example 20 with WorkspaceImpl

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

the class WorkspaceTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, EnvironmentRecipeImpl.class, ExtendedMachineImpl.class, SourceStorageImpl.class, ServerConf2Impl.class, StackImpl.class, CommandImpl.class, SnapshotImpl.class, RecipeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").setExceptionHandler(H2ExceptionHandler.class).build());
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new WorkspaceRepository());
    bind(new TypeLiteral<TckRepository<StackImpl>>() {
    }).toInstance(new StackRepository());
    bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
    bind(StackDao.class).to(JpaStackDao.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) StackDao(org.eclipse.che.api.workspace.server.spi.StackDao) WorkspaceDao(org.eclipse.che.api.workspace.server.spi.WorkspaceDao)

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