Search in sources :

Example 6 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project devspaces-images by redhat-developer.

the class JpaWorkerDaoTest method shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Database exception")
public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod() throws Exception {
    final Account account = new AccountImpl("accountId", "namespace", "test");
    final WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspaceId").setAccount(account).build();
    // Persist the account
    manager.getTransaction().begin();
    manager.persist(account);
    manager.getTransaction().commit();
    manager.clear();
    // Persist the workspace
    manager.getTransaction().begin();
    manager.persist(workspace);
    manager.getTransaction().commit();
    manager.clear();
    final UserImpl user = new UserImpl("user0", "user0@com.com", "usr0");
    // Persist the user
    manager.getTransaction().begin();
    manager.persist(user);
    manager.getTransaction().commit();
    manager.clear();
    // Persist the worker
    WorkerImpl worker = new WorkerImpl("workspaceId", "user0", Collections.singletonList(SET_PERMISSIONS));
    manager.getTransaction().begin();
    manager.persist(worker);
    manager.getTransaction().commit();
    manager.clear();
    workerDao.exists("user0", "workspaceId", SET_PERMISSIONS);
}
Also used : Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Test(org.testng.annotations.Test)

Example 7 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project devspaces-images by redhat-developer.

the class RemoveWorkersBeforeWorkspaceRemovedEventSubscriberTest method setupEntities.

@BeforeClass
public void setupEntities() throws Exception {
    account = new AccountImpl("account1", "accountName", "test");
    users = new UserImpl[] { new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2") };
    workspace = new WorkspaceImpl("ws1", account, new WorkspaceConfigImpl("", "", "cfg1", null, null, null, null));
    workers = new WorkerImpl[] { new WorkerImpl("ws1", "user1", Arrays.asList("read", "use", "run")), new WorkerImpl("ws1", "user2", Arrays.asList("read", "use")) };
    Injector injector = Guice.createInjector(new JpaTckModule());
    manager = injector.getInstance(EntityManager.class);
    workerDao = injector.getInstance(JpaWorkerDao.class);
    workspaceDao = injector.getInstance(JpaWorkspaceDao.class);
    subscriber = injector.getInstance(RemoveWorkersBeforeWorkspaceRemovedEventSubscriber.class);
    subscriber.subscribe();
    tckResourcesCleaner = injector.getInstance(TckResourcesCleaner.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EntityManager(javax.persistence.EntityManager) JpaWorkspaceDao(org.eclipse.che.api.workspace.server.jpa.JpaWorkspaceDao) Injector(com.google.inject.Injector) AccountImpl(org.eclipse.che.account.spi.AccountImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) RemoveWorkersBeforeWorkspaceRemovedEventSubscriber(org.eclipse.che.multiuser.permission.workspace.server.spi.jpa.JpaWorkerDao.RemoveWorkersBeforeWorkspaceRemovedEventSubscriber) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project devspaces-images by redhat-developer.

the class WorkerDaoTest method shouldStoreWorker.

/* WorkerDao.store() tests */
@Test
public void shouldStoreWorker() throws Exception {
    WorkerImpl worker = new WorkerImpl("ws0", "user0", Arrays.asList("read", "use", "run"));
    workerDao.store(worker);
    Assert.assertEquals(workerDao.getWorker("ws0", "user0"), new WorkerImpl(worker));
}
Also used : WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Test(org.testng.annotations.Test)

Example 9 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project devspaces-images by redhat-developer.

the class WorkerDaoTest method shouldReplaceExistingWorkerOnStoring.

@Test
public void shouldReplaceExistingWorkerOnStoring() throws Exception {
    WorkerImpl replace = new WorkerImpl("ws1", "user1", Collections.singletonList("read"));
    workerDao.store(replace);
    Assert.assertEquals(workerDao.getWorker("ws1", "user1"), replace);
}
Also used : WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl) Test(org.testng.annotations.Test)

Example 10 with WorkerImpl

use of org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl in project devspaces-images by redhat-developer.

the class JpaWorkerDao method get.

@Override
public WorkerImpl get(String userId, String instanceId) throws ServerException, NotFoundException {
    requireNonNull(instanceId, "Workspace identifier required");
    requireNonNull(userId, "User identifier required");
    try {
        return new WorkerImpl(getEntity(wildcardToNull(userId), instanceId));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) WorkerImpl(org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl)

Aggregations

WorkerImpl (org.eclipse.che.multiuser.permission.workspace.server.model.impl.WorkerImpl)26 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)18 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 AccountImpl (org.eclipse.che.account.spi.AccountImpl)16 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)12 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)10 TypeLiteral (com.google.inject.TypeLiteral)8 DBInitializer (org.eclipse.che.core.db.DBInitializer)8 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)8 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)8 WorkerDao (org.eclipse.che.multiuser.permission.workspace.server.spi.WorkerDao)8 WorkerDaoTest (org.eclipse.che.multiuser.permission.workspace.server.spi.tck.WorkerDaoTest)8 JpaWorkerDao (org.eclipse.che.multiuser.permission.workspace.server.spi.jpa.JpaWorkerDao)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 HashMap (java.util.HashMap)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4 SerializableConverter (org.eclipse.che.api.workspace.server.devfile.SerializableConverter)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)4 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)4