Search in sources :

Example 1 with TransactionAccountFromModel

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

the class GaeModelTest method testTransactionSaveFailure.

public void testTransactionSaveFailure() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    accFrom.insert();
    try {
        accFrom.getPersistenceManager().beginTransaction();
        accFrom.amount -= 100L;
        accFrom.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);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException) TransactionAccountFromModel(siena.base.test.model.TransactionAccountFromModel)

Example 2 with TransactionAccountFromModel

use of siena.base.test.model.TransactionAccountFromModel 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 3 with TransactionAccountFromModel

use of siena.base.test.model.TransactionAccountFromModel 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 4 with TransactionAccountFromModel

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

the class GaeModelTest method testTransactionSave.

// SPECIFIC TESTS FOR GAE (transaction on one entity in a given group)
public void testTransactionSave() {
    TransactionAccountFromModel accFrom = new TransactionAccountFromModel(1000L);
    accFrom.insert();
    try {
        accFrom.getPersistenceManager().beginTransaction();
        accFrom.amount -= 100L;
        accFrom.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);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException) TransactionAccountFromModel(siena.base.test.model.TransactionAccountFromModel)

Aggregations

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