use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class SqlCriteriaTest method assertCriteria.
@Override
public void assertCriteria(final long expected, final Criteria<Movie2> criteria) {
try (VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
final long count = storeManager.getDataStore().find(dtDefinitionMovie, criteria).size();
Assert.assertEquals(expected, count);
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class HibernateConnectionProviderTest method ping.
@Test
public void ping() throws SQLException {
final SqlConnectionProvider sqlConnectionProvider = sqlDataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME);
final String testQuery = sqlConnectionProvider.getDataBase().getSqlDialect().getTestQuery();
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final SqlConnection connection = sqlConnectionProvider.obtainConnection();
try {
sqlDataBaseManager.executeQuery(SqlStatement.builder(testQuery).build(), Integer.class, 1, connection);
} finally {
connection.release();
}
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AccountManagerTest method testLoginSuccess.
@Test
public void testLoginSuccess() {
try (VTransactionWritable tx = obtainTx()) {
final Optional<Account> accountAdmin = accountManager.getAccountByAuthToken("admin");
final Optional<Account> accountBill = accountManager.getAccountByAuthToken("bill.clinton@yopmail.com");
Assert.assertTrue("Authent fail", accountAdmin.isPresent() || accountBill.isPresent());
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractKVStoreManagerTest method testRemove.
@Test
public void testRemove() {
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Optional<Flower> flower = kvStoreManager.find("flowers", "10", Flower.class);
Assert.assertFalse("There is already a flower id 10", flower.isPresent());
kvStoreManager.put("flowers", "10", buildFlower("daisy", 60));
kvStoreManager.put("flowers", "11", buildFlower("tulip", 100));
final Optional<Flower> flower1 = kvStoreManager.find("flowers", "10", Flower.class);
final Optional<Flower> flower2 = kvStoreManager.find("flowers", "11", Flower.class);
Assert.assertTrue("Flower id 10 not found", flower1.isPresent());
Assert.assertTrue("Flower id 11 not found", flower2.isPresent());
transaction.commit();
}
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Optional<Flower> flower = kvStoreManager.find("flowers", "10", Flower.class);
Assert.assertTrue("Flower id 10 not found", flower.isPresent());
kvStoreManager.remove("flowers", "10");
final Optional<Flower> flower1 = kvStoreManager.find("flowers", "10", Flower.class);
final Optional<Flower> flower2 = kvStoreManager.find("flowers", "11", Flower.class);
Assert.assertFalse("Remove flower id 10 failed", flower1.isPresent());
Assert.assertTrue("Flower id 11 not found", flower2.isPresent());
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractKVStoreManagerTest method testCount.
@Test
public void testCount() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final int nbFlowers = kvStoreManager.count("flowers");
Assert.assertEquals(0, nbFlowers);
final Flower tulip1 = buildFlower("tulip", 100);
kvStoreManager.put("flowers", "1", tulip1);
final Flower tulip2 = buildFlower("tulip", 110);
kvStoreManager.put("flowers", "2", tulip2);
final Flower tulip3 = buildFlower("tulip", 120);
kvStoreManager.put("flowers", "3", tulip3);
// count after 3 inserts
final int nbFlowers2 = kvStoreManager.count("flowers");
Assert.assertEquals(3, nbFlowers2);
// count after 1 more insert of same value
kvStoreManager.put("flowers", "4", tulip3);
final int nbFlowers3 = kvStoreManager.count("flowers");
Assert.assertEquals(4, nbFlowers3);
// count after 1 insert of same key : update
kvStoreManager.put("flowers", "3", tulip3);
final int nbFlowers4 = kvStoreManager.count("flowers");
Assert.assertEquals(4, nbFlowers4);
}
}
Aggregations