Search in sources :

Example 21 with UserDevfilePermissionImpl

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

the class JpaUserDevfilePermissionDaoTest method shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Database exception")
public void shouldThrowServerExceptionOnExistsWhenRuntimeExceptionOccursInDoGetMethod() throws Exception {
    // Persist the account
    manager.getTransaction().begin();
    manager.persist(TestObjectGenerator.TEST_ACCOUNT);
    manager.getTransaction().commit();
    manager.clear();
    final UserDevfileImpl userDevfile = TestObjectGenerator.createUserDevfile();
    // Persist the userdevfile
    manager.getTransaction().begin();
    manager.persist(userDevfile);
    manager.getTransaction().commit();
    manager.clear();
    final UserImpl user = new UserImpl(generate("user", 6), "user0@com.com", "usr0");
    // Persist the user
    manager.getTransaction().begin();
    manager.persist(user);
    manager.getTransaction().commit();
    manager.clear();
    // Persist the worker
    UserDevfilePermissionImpl worker = new UserDevfilePermissionImpl(userDevfile.getId(), user.getId(), Collections.singletonList(SET_PERMISSIONS));
    manager.getTransaction().begin();
    manager.persist(worker);
    manager.getTransaction().commit();
    manager.clear();
    userDevfilePermissionsDao.exists(user.getId(), userDevfile.getId(), SET_PERMISSIONS);
}
Also used : UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) Test(org.testng.annotations.Test)

Example 22 with UserDevfilePermissionImpl

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

the class RemoveUserDevfilePermissionsBeforeUserDevfileRemovedEventSubscriberTest method setupEntities.

@BeforeClass
public void setupEntities() throws Exception {
    users = new UserImpl[] { new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2") };
    userDevfile = TestObjectGenerator.createUserDevfile("devfile_id1", generate("name", 6));
    userDevfilePermissions = new UserDevfilePermissionImpl[] { new UserDevfilePermissionImpl(userDevfile.getId(), "user1", Arrays.asList("read", "use", "run")), new UserDevfilePermissionImpl(userDevfile.getId(), "user2", Arrays.asList("read", "use")) };
    Injector injector = Guice.createInjector(new JpaTckModule());
    manager = injector.getInstance(EntityManager.class);
    userDevfilePermissionsDao = injector.getInstance(JpaUserDevfilePermissionDao.class);
    userDevfileDao = injector.getInstance(JpaUserDevfileDao.class);
    subscriber = injector.getInstance(RemoveUserDevfilePermissionsBeforeUserDevfileRemovedEventSubscriber.class);
    subscriber.subscribe();
    tckResourcesCleaner = injector.getInstance(TckResourcesCleaner.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) EntityManager(javax.persistence.EntityManager) JpaUserDevfileDao(org.eclipse.che.api.devfile.server.jpa.JpaUserDevfileDao) RemoveUserDevfilePermissionsBeforeUserDevfileRemovedEventSubscriber(org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.JpaUserDevfilePermissionDao.RemoveUserDevfilePermissionsBeforeUserDevfileRemovedEventSubscriber) Injector(com.google.inject.Injector) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 23 with UserDevfilePermissionImpl

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

the class UserDevfilePermissionDaoTest method shouldReplaceExistingPermissionOnStoring.

@Test
public void shouldReplaceExistingPermissionOnStoring() throws Exception {
    UserDevfilePermissionImpl replace = new UserDevfilePermissionImpl("devfile_id1", "user1", Collections.singletonList("READ"));
    permissionDao.store(replace);
    Assert.assertEquals(permissionDao.getUserDevfilePermission("devfile_id1", "user1"), replace);
}
Also used : UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) Test(org.testng.annotations.Test)

Example 24 with UserDevfilePermissionImpl

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

the class UserDevfilePermissionDaoTest method shouldStorePermissions.

@Test
public void shouldStorePermissions() throws Exception {
    UserDevfilePermissionImpl permission = new UserDevfilePermissionImpl("devfile_id1", "user0", Arrays.asList(READ, DELETE, UPDATE));
    permissionDao.store(permission);
    Assert.assertEquals(permissionDao.getUserDevfilePermission("devfile_id1", "user0"), new UserDevfilePermissionImpl(permission));
}
Also used : UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) Test(org.testng.annotations.Test)

Example 25 with UserDevfilePermissionImpl

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

the class JpaUserDevfilePermissionDao method get.

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

Aggregations

UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)26 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)16 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)12 AccountImpl (org.eclipse.che.account.spi.AccountImpl)10 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)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 UserDevfilePermissionDao (org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao)8 EntityManager (javax.persistence.EntityManager)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)6 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)6 Test (org.testng.annotations.Test)6 UserDevfilePermission (org.eclipse.che.multiuser.permission.devfile.server.model.UserDevfilePermission)5 JpaUserDevfilePermissionDao (org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.JpaUserDevfilePermissionDao)5 Injector (com.google.inject.Injector)4 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)4 HashMap (java.util.HashMap)4