Search in sources :

Example 41 with TransactionAccountFrom

use of siena.base.test.model.TransactionAccountFrom 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)

Example 42 with TransactionAccountFrom

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

the class GaeTest method testTransactionSave.

public void testTransactionSave() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    pm.insert(accFrom);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount -= 100L;
        pm.save(accFrom);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(900L == accFromAfter.amount);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 43 with TransactionAccountFrom

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

the class GaeTest method testTransactionUpdate.

@Override
public void testTransactionUpdate() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    pm.insert(accFrom);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount -= 100L;
        pm.update(accFrom);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } finally {
        pm.closeConnection();
    }
    TransactionAccountFrom accFromAfter = pm.getByKey(TransactionAccountFrom.class, accFrom.id);
    assertTrue(900L == accFromAfter.amount);
}
Also used : TransactionAccountFrom(siena.base.test.model.TransactionAccountFrom) SienaException(siena.SienaException)

Example 44 with TransactionAccountFrom

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

the class GaeTest method testTransactionSaveBatchFailure.

public void testTransactionSaveBatchFailure() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    pm.insert(accFrom);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount -= 100L;
        pm.save(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 45 with TransactionAccountFrom

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

the class GaeTest method testTransactionInsertBatch.

public void testTransactionInsertBatch() {
    TransactionAccountFrom accFrom = new TransactionAccountFrom(1000L);
    try {
        pm.beginTransaction(Connection.TRANSACTION_READ_COMMITTED);
        accFrom.amount = 1000L;
        pm.insert(accFrom);
        pm.commitTransaction();
    } catch (SienaException e) {
        pm.rollbackTransaction();
        fail();
    } 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)

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