Search in sources :

Example 31 with TransactionAccountTo

use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.

the class BaseModelTest method testTransactionSave.

public void testTransactionSave() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    TransactionAccountToModel accTo = new TransactionAccountToModel(1000L);
    accFrom.insert();
    accTo.insert();
    try {
        accFrom.getPersistenceManager().beginTransaction();
        accFrom.amount -= 100L;
        accFrom.save();
        accTo.amount += 100L;
        accTo.save();
        accFrom.getPersistenceManager().commitTransaction();
    } catch (SienaException e) {
        accFrom.getPersistenceManager().rollbackTransaction();
        fail();
    } finally {
        accFrom.getPersistenceManager().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);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) TransactionAccountToModel(siena.base.test.model.TransactionAccountToModel) SienaException(siena.SienaException) TransactionAccountFromModel(siena.base.test.model.TransactionAccountFromModel)

Example 32 with TransactionAccountTo

use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.

the class BaseModelTest method testTransactionSaveFailure.

public void testTransactionSaveFailure() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    TransactionAccountToModel accTo = new TransactionAccountToModel(1000L);
    accFrom.insert();
    accTo.insert();
    try {
        accFrom.getPersistenceManager().beginTransaction();
        accFrom.amount -= 100L;
        accFrom.save();
        accTo.amount += 100L;
        accTo.save();
        throw new SienaException("test");
    } catch (SienaException e) {
        accFrom.getPersistenceManager().rollbackTransaction();
    } finally {
        accFrom.getPersistenceManager().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);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) TransactionAccountToModel(siena.base.test.model.TransactionAccountToModel) SienaException(siena.SienaException) TransactionAccountFromModel(siena.base.test.model.TransactionAccountFromModel)

Example 33 with TransactionAccountTo

use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.

the class BaseTest method testTransactionInsertBatch.

public void testTransactionInsertBatch() {
    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);
        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);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 34 with TransactionAccountTo

use of siena.base.test.model.TransactionAccountTo in project siena by mandubian.

the class BaseTest method testTransactionDeleteBatchFailure.

public void testTransactionDeleteBatchFailure() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    TransactionAccountTo accTo = new TransactionAccountTo(100L);
    pm.insert(accFrom, accTo);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        pm.delete(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(100L == accToAfter.amount);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Aggregations

SienaException (siena.SienaException)34 TransactionAccountFrom (siena.base.test.model.TransactionAccountFrom)34 TransactionAccountTo (siena.base.test.model.TransactionAccountTo)34 TransactionAccountFromModel (siena.base.test.model.TransactionAccountFromModel)2 TransactionAccountToModel (siena.base.test.model.TransactionAccountToModel)2