Search in sources :

Example 16 with AccountImpl

use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.

the class JpaWorkspaceDaoTest method shouldSyncDbAttributesWhileUpdatingWorkspace.

@Test
public void shouldSyncDbAttributesWhileUpdatingWorkspace() throws Exception {
    final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
    final WorkspaceImpl workspace = createWorkspace("id", account, "name");
    // persist the workspace
    manager.getTransaction().begin();
    manager.persist(account);
    manager.persist(workspace);
    manager.getTransaction().commit();
    manager.clear();
    // put a new attribute
    workspace.getConfig().getProjects().get(0).getAttributes().put("new-attr", singletonList("value"));
    workspaceDao.update(workspace);
    manager.clear();
    // check it's okay
    assertEquals(workspaceDao.get(workspace.getId()).getConfig().getProjects().get(0).getAttributes().size(), 3);
}
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 17 with AccountImpl

use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.

the class JpaWorkspaceDaoTest method shouldCascadeRemoveObjectsWhenTheyRemovedFromEntity.

@Test
public void shouldCascadeRemoveObjectsWhenTheyRemovedFromEntity() {
    final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
    final WorkspaceImpl workspace = createWorkspace("id", account, "name");
    // 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();
    // Cleanup one to many dependencies
    manager.getTransaction().begin();
    final WorkspaceConfigImpl config = workspace.getConfig();
    config.getProjects().clear();
    config.getCommands().clear();
    config.getEnvironments().clear();
    manager.merge(workspace);
    manager.getTransaction().commit();
    manager.clear();
    // If all the One To Many dependencies are removed then all the embedded objects
    // which depend on those object are also removed, which guaranteed by foreign key constraints
    assertEquals(asLong("SELECT COUNT(p) FROM ProjectConfig p"), 0L, "Project configs");
    assertEquals(asLong("SELECT COUNT(c) FROM Command c"), 0L, "Commands");
    assertEquals(asLong("SELECT COUNT(e) FROM Environment e"), 0L, "Environments");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test)

Example 18 with AccountImpl

use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.

the class AccountDaoTest method shouldUpdateAccount.

@Test(dependsOnMethods = "shouldGetAccountById")
public void shouldUpdateAccount() throws Exception {
    AccountImpl account = accounts[0];
    account.setName("newName");
    account.setType("newType");
    accountDao.update(account);
    assertEquals(account, accountDao.getById(account.getId()));
}
Also used : AccountImpl(org.eclipse.che.account.spi.AccountImpl) Test(org.testng.annotations.Test)

Example 19 with AccountImpl

use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.

the class AccountDaoTest method shouldGetAccountById.

@Test
public void shouldGetAccountById() throws Exception {
    final AccountImpl account = accounts[0];
    final AccountImpl found = accountDao.getById(account.getId());
    assertEquals(account, found);
}
Also used : AccountImpl(org.eclipse.che.account.spi.AccountImpl) Test(org.testng.annotations.Test)

Example 20 with AccountImpl

use of org.eclipse.che.account.spi.AccountImpl in project che by eclipse.

the class AccountDaoTest method setUp.

@BeforeMethod
private void setUp() throws TckRepositoryException {
    accounts = new AccountImpl[2];
    accounts[0] = new AccountImpl(NameGenerator.generate("account", 10), "test1", "test");
    accounts[1] = new AccountImpl(NameGenerator.generate("account", 10), "test2", "test");
    accountRepo.createAll(asList(accounts));
}
Also used : AccountImpl(org.eclipse.che.account.spi.AccountImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

AccountImpl (org.eclipse.che.account.spi.AccountImpl)27 Test (org.testng.annotations.Test)13 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)12 BeforeMethod (org.testng.annotations.BeforeMethod)5 TypeLiteral (com.google.inject.TypeLiteral)4 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)4 DBInitializer (org.eclipse.che.core.db.DBInitializer)4 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)4 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)4 Transactional (com.google.inject.persist.Transactional)3 EntityManager (javax.persistence.EntityManager)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 AccountDao (org.eclipse.che.account.spi.AccountDao)2 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)2 ServerException (org.eclipse.che.api.core.ServerException)2 Workspace (org.eclipse.che.api.core.model.workspace.Workspace)2 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)2 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)2 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)2 RecipeDao (org.eclipse.che.api.machine.server.spi.RecipeDao)2