use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.
the class BaseTest method testTransactionInsert.
public void testTransactionInsert() {
TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
TransactionAccountTo accTo = new TransactionAccountTo(1000L);
try {
pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
accFrom.amount = 1000L;
accTo.amount = 100L;
pm.insert(accFrom);
pm.insert(accTo);
pm.commitTransaction();
} catch (SienaException e) {
pm.rollbackTransaction();
fail();
} finally {
pm.closeConnection();
}
TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
assertTrue(1000L == accFromAfter.amount);
TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
assertTrue(100L == accToAfter.amount);
}
use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.
the class BaseTest method testTransactionSave.
public void testTransactionSave() {
TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
TransactionAccountTo accTo = new TransactionAccountTo(1000L);
pm.insert(accFrom, accTo);
try {
pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
accFrom.amount -= 100L;
pm.save(accFrom);
accTo.amount += 100L;
pm.save(accTo);
pm.commitTransaction();
} catch (SienaException e) {
pm.rollbackTransaction();
fail();
} finally {
pm.closeConnection();
}
TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
assertTrue(900L == accFromAfter.amount);
TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
assertTrue(1100L == accToAfter.amount);
}
use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.
the class BaseTest method testTransactionUpdateBatchFailure.
public void testTransactionUpdateBatchFailure() {
TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
TransactionAccountTo accTo = new TransactionAccountTo(1000L);
pm.insert(accFrom, accTo);
try {
pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
accFrom.amount -= 100L;
accTo.amount += 100L;
pm.update(accFrom, accTo);
throw new SienaException("test");
} catch (SienaException e) {
pm.rollbackTransaction();
} finally {
pm.closeConnection();
}
TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
assertTrue(1000L == accFromAfter.amount);
TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
assertTrue(1000L == accToAfter.amount);
}
use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.
the class BaseTest method testTransactionUpdate.
public void testTransactionUpdate() {
TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
TransactionAccountTo accTo = new TransactionAccountTo(1000L);
pm.insert(accFrom, accTo);
try {
pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
accFrom.amount -= 100L;
pm.update(accFrom);
accTo.amount += 100L;
pm.update(accTo);
pm.commitTransaction();
} catch (SienaException e) {
pm.rollbackTransaction();
fail();
} finally {
pm.closeConnection();
}
TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
assertTrue(900L == accFromAfter.amount);
TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
assertTrue(1100L == accToAfter.amount);
}
use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.
the class BaseTest method testTransactionInsertBatchFailure.
public void testTransactionInsertBatchFailure() {
TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
TransactionAccountTo accTo = new TransactionAccountTo(1000L);
try {
pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
accFrom.amount = 1000L;
accTo.amount = 100L;
pm.insert(accFrom, accTo);
throw new SienaException("test");
} catch (SienaException e) {
pm.rollbackTransaction();
} finally {
pm.closeConnection();
}
TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
assertNull(accFromAfter);
TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
assertNull(accToAfter);
}
Aggregations