Search in sources :

Example 6 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 setUp.

@BeforeMethod
public void setUp() throws TckRepositoryException {
    accountRepository.createAll(ImmutableList.of(TestObjectGenerator.TEST_ACCOUNT));
    permissions = new UserDevfilePermissionImpl[] { new UserDevfilePermissionImpl("devfile_id1", "user1", Arrays.asList(READ, DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id1", "user2", Arrays.asList(READ, DELETE)), new UserDevfilePermissionImpl("devfile_id2", "user1", Arrays.asList(READ, UPDATE)), new UserDevfilePermissionImpl("devfile_id2", "user2", Arrays.asList(READ, DELETE, UPDATE)), new UserDevfilePermissionImpl("devfile_id2", "user0", Arrays.asList(READ, DELETE, UPDATE)) };
    final UserImpl[] users = new UserImpl[] { new UserImpl("user0", "user0@com.com", "usr0"), new UserImpl("user1", "user1@com.com", "usr1"), new UserImpl("user2", "user2@com.com", "usr2") };
    userRepository.createAll(Arrays.asList(users));
    devfileRepository.createAll(ImmutableList.of(createUserDevfile("devfile_id1", generate("name", 6)), createUserDevfile("devfile_id2", generate("name", 6)), createUserDevfile("devfile_id3", generate("name", 6)), createUserDevfile("devfile_id4", generate("name", 6)), createUserDevfile("devfile_id5", generate("name", 6))));
    permissionTckRepository.createAll(Stream.of(permissions).map(UserDevfilePermissionImpl::new).collect(Collectors.toList()));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with UserDevfilePermissionImpl

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

the class UserDevfileTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, UserImpl.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, MachineConfigImpl.class, SourceStorageImpl.class, ServerConfigImpl.class, CommandImpl.class, RecipeImpl.class, VolumeImpl.class, // devfile
    UserDevfileImpl.class, UserDevfilePermissionImpl.class, ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").addClass(SerializableConverter.class).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<UserDevfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfileImpl.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<UserDevfilePermissionImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfilePermissionImpl.class));
    bind(new TypeLiteral<AbstractPermissionsDomain<UserDevfilePermissionImpl>>() {
    }).to(UserDevfilePermissionDaoTest.TestDomain.class);
    bind(UserDevfilePermissionDao.class).to(JpaUserDevfilePermissionDao.class);
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) JpaUserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.jpa.JpaUserDevfilePermissionDao) UserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) UserDevfilePermissionDaoTest(org.eclipse.che.multiuser.permission.devfile.server.spi.tck.UserDevfilePermissionDaoTest) 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) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) SourceImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 8 with UserDevfilePermissionImpl

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

the class JpaTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, UserImpl.class, UserDevfilePermissionImpl.class, // devfile
    ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, UserDevfileImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(new TypeLiteral<AbstractPermissionsDomain<UserDevfilePermissionImpl>>() {
    }).to(UserDevfilePermissionDaoTest.TestDomain.class);
    bind(UserDevfilePermissionDao.class).to(JpaUserDevfilePermissionDao.class);
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<UserDevfilePermission>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfilePermission.class));
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<UserDevfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserDevfileImpl.class));
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) UserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao) AccountImpl(org.eclipse.che.account.spi.AccountImpl) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) UserDevfilePermission(org.eclipse.che.multiuser.permission.devfile.server.model.UserDevfilePermission) UserDevfilePermissionDaoTest(org.eclipse.che.multiuser.permission.devfile.server.spi.tck.UserDevfilePermissionDaoTest) 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) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) 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)

Example 9 with UserDevfilePermissionImpl

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

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 10 with UserDevfilePermissionImpl

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

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)

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