Search in sources :

Example 6 with TransactionAccountFrom

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

the class GaeTest method testTransactionDeleteBatchFailure.

public void testTransactionDeleteBatchFailure() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    pm.insert(accFrom);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        pm.delete(accFrom);
        throw new SienaException("test");
    } catch (SienaException e) {
        pm.rollbackTransaction();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(1000L == accFromAfter.amount);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 7 with TransactionAccountFrom

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

the class BaseTest method testTransactionDelete.

public void testTransactionDelete() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    TransactionAccountTo accTo = new TransactionAccountTo(1000L);
    pm.insert(accFrom, accTo);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        pm.delete(accFrom);
        pm.delete(accTo);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertNull(accFromAfter);
    TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
    assertNull(accToAfter);
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 8 with TransactionAccountFrom

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionSaveFailure.

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

Example 9 with TransactionAccountFrom

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionUpdate.

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

Example 10 with TransactionAccountFrom

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

the class BaseTestNoAutoInc_10_TRANSACTION method testTransactionDelete.

public void testTransactionDelete() {
    if (supportsTransaction()) {
        TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
        TransactionAccountTo accTo = new TransactionAccountTo(1000L);
        pm.insert(accFrom, accTo);
        try {
            pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
            pm.delete(accFrom);
            pm.delete(accTo);
            pm.commitTransaction();
        } catch (SienaException e) {
            pm.rollbackTransaction();
            fail();
        } finally {
            pm.closeConnection();
        }
        TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
        assertNull(accFromAfter);
        TransactionAccountTo accToAfter = pm.getByKey(TransactionAccountTo.class, accTo.id);
        assertNull(accToAfter);
    }
}
Also used : TransactionAccountTo(siena.base.test.model.TransactionAccountTo) TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Aggregations

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