Search in sources :

Example 1 with TestBean

use of org.apache.aries.transaction.test.TestBean in project aries by apache.

the class AbstractIntegrationTest method assertInsertFails.

protected void assertInsertFails() throws Exception {
    TestBean bean = getBean();
    int initialRows = counter.countRows();
    if (clientTransaction) {
        tran.begin();
    }
    try {
        bean.insertRow("testWithClientTran", 1, null);
        fail("IllegalStateException not thrown");
    } catch (IllegalStateException e) {
    // Ignore Expected
    }
    if (clientTransaction) {
        tran.commit();
    }
    int finalRows = counter.countRows();
    assertEquals("Added rows", 0, finalRows - initialRows);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean)

Example 2 with TestBean

use of org.apache.aries.transaction.test.TestBean in project aries by apache.

the class AbstractIntegrationTest method assertInsertWithAppExceptionCommitted.

protected void assertInsertWithAppExceptionCommitted() throws Exception {
    TestBean bean = getBean();
    int initialRows = counter.countRows();
    if (clientTransaction) {
        tran.begin();
    }
    bean.insertRow("testWithClientTranAndWithAppException", 1, null);
    try {
        bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
    } catch (SQLException e) {
        Assert.assertEquals("Dummy exception", e.getMessage());
    }
    if (clientTransaction) {
        tran.commit();
    }
    int finalRows = counter.countRows();
    assertEquals("Added rows", 2, finalRows - initialRows);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean) SQLException(java.sql.SQLException)

Example 3 with TestBean

use of org.apache.aries.transaction.test.TestBean in project aries by apache.

the class AbstractIntegrationTest method assertDelegateInsert.

protected void assertDelegateInsert() throws Exception {
    TestBean bean = getBean();
    int initialRows = counter.countRows();
    tran.begin();
    bean.delegateInsertRow("testWithClientTran", 1);
    tran.commit();
    int finalRows = counter.countRows();
    assertEquals("Added rows", 1, finalRows - initialRows);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean)

Example 4 with TestBean

use of org.apache.aries.transaction.test.TestBean in project aries by apache.

the class AbstractIntegrationTest method assertDelegateInsertFails.

// Test without client transaction - the insert fails because the bean delegates to another
// bean with a transaction strategy of Mandatory, and no transaction is available
protected void assertDelegateInsertFails() throws Exception {
    TestBean bean = getBean();
    int initialRows = counter.countRows();
    if (clientTransaction) {
        tran.begin();
    }
    try {
        bean.delegateInsertRow("testWithoutClientTran", 1);
        fail("IllegalStateException not thrown");
    } catch (IllegalStateException e) {
    // Ignore expected
    }
    if (clientTransaction) {
        tran.commit();
    }
    int finalRows = counter.countRows();
    assertEquals("Added rows", 0, finalRows - initialRows);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean)

Example 5 with TestBean

use of org.apache.aries.transaction.test.TestBean in project aries by apache.

the class AbstractIntegrationTest method assertInsertSuccesful.

protected void assertInsertSuccesful() throws Exception {
    TestBean bean = getBean();
    int initialRows = counter.countRows();
    if (clientTransaction) {
        tran.begin();
    }
    bean.insertRow("testWithClientTran", 1, null);
    if (clientTransaction) {
        tran.commit();
    }
    int finalRows = counter.countRows();
    assertEquals("Added rows", 1, finalRows - initialRows);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean)

Aggregations

TestBean (org.apache.aries.transaction.test.TestBean)6 SQLException (java.sql.SQLException)1 RollbackException (javax.transaction.RollbackException)1