Package org.apache.aries.transaction.test

Examples of org.apache.aries.transaction.test.TestBean


public class NeverTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testNever() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Never)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - an exception is thrown because transactions are not allowed
      int initialRows = bean.countRows();
     
      tran.begin();
     
      try {
          bean.insertRow("testWithClientTran", 1);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //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
      initialRows = bean.countRows();

      try {
          bean.insertRow("testWithoutClientTran", 1, true);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
  }
View Full Code Here


public class RequiresNewTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testRequiresNew() throws Exception {
      TestBean rnBean = getOsgiService(TestBean.class, "(tranAttribute=RequiresNew)", DEFAULT_TIMEOUT);
      TestBean rBean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - a container transaction is used to insert the row
      int initialRows = rnBean.countRows();
     
      tran.begin();
      rnBean.insertRow("testWithClientTran", 1);
      tran.rollback();
     
      int finalRows = rnBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and application exception - the container transaction is committed,
      //the user transaction is not affected.
      initialRows = rnBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          rnBean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = rnBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
     
      //Test with client transaction and runtime exception - the container transaction is rolled back,
      //the user transaction is not affected
      initialRows = rnBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          rnBean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
      } catch (RuntimeException e) {
          e.printStackTrace();
View Full Code Here

public class SupportsTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testSupports() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Supports)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - the insert succeeds because the bean delegates to
      //another bean with a transaction strategy of Mandatory, and the user transaction
      //is delegated
      int initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTran", 1, true);
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and application exception - the user transaction is not rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException());
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
     
      //Test with client transaction and runtime exception - the user transaction is rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException());
      } catch (RuntimeException e) {
          e.printStackTrace();
      }
     
      try {
          tran.commit();
          fail("RollbackException not thrown");
      } catch (RollbackException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //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
      initialRows = bean.countRows();
     
      try {
          bean.insertRow("testWithoutClientTran", 1, true);
          fail("Exception not thrown");
      } catch (Exception e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
  }
View Full Code Here

public class InvalidTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testInvalid() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Invalid)", DEFAULT_TIMEOUT);
     
      //Test without client transaction - an exception is thrown because the bean is not
      //configured correctly, i.e. multiple transaction elements match to the same method
      //name.
      try {
          bean.insertRow("testWithoutClientTran", 1);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
  }
View Full Code Here

public class MandatoryTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testMandatory() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Mandatory)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - the user transaction is used to insert a row
      int initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTran", 1);
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
 
      //Test with client transaction and application exception - the user transaction is not rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
     
      //Test with client transaction and runtime exception - the user transaction is rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
      } catch (RuntimeException e) {
          e.printStackTrace();
      }
     
      try {
          tran.commit();
          fail("RollbackException not thrown");
      } catch (RollbackException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //Test without client transaction - an exception is thrown because a transaction is mandatory
      try {
          bean.insertRow("testWithoutClientTran", 1);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
  }
View Full Code Here

public class NotSupportedTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testNotSupported() throws Exception {
      TestBean nsBean = getOsgiService(TestBean.class, "(tranAttribute=NotSupported)", DEFAULT_TIMEOUT);
      TestBean rBean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - the insert fails because the bean delegates to another
      //bean with a transaction strategy of Mandatory, and no transaction is available, i.e.
      //the user transaction is not propagated, and there is no container transaction.
      int initialRows = nsBean.countRows();
     
      tran.begin();
     
      try {
          nsBean.insertRow("testWithClientTran", 1, true);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      int finalRows = nsBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //Test with client transaction and with application exception - the user transaction is not
      //marked for rollback and can still be committed
      initialRows = nsBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          nsBean.throwApplicationException();
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = nsBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and with runtime exception - the user transaction is not
      //marked for rollback and can still be committed
      initialRows = nsBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          nsBean.throwRuntimeException();
      } catch (RuntimeException e) {
          e.printStackTrace();
View Full Code Here

public class RequiredTranAttributeTest extends AbstractIntegrationTest {
 
  @Test
  public void testRequired() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranAttribute=Required)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - the user transaction is used to insert a row
      int initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTran", 1);
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and application exception - the user transaction is not rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException());
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
      
      //Test with client transaction and runtime exception - the user transaction is rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException());
      } catch (RuntimeException e) {
          e.printStackTrace();
      }
     
      try {
          tran.commit();
          fail("RollbackException not thrown");
      } catch (RollbackException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //Test without client exception - a container transaction is used to insert the row
      initialRows = bean.countRows();
     
      bean.insertRow("testWithoutClientTran", 1);
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test without client exception and with application exception - the container transaction is not rolled back
      initialRows = bean.countRows();
     
      try {
          bean.insertRow("testWithoutClientTranAndWithAppException", 1, new SQLException("Dummy exception"));
      } catch (Exception e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test without client transaction and with runtime exception - the container transaction is rolled back
      initialRows = bean.countRows();
     
      try {
          bean.insertRow("testWithoutClientTranAndWithRuntimeException", 1, new RuntimeException("Dummy exception"));
      } catch (Exception e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
  }
View Full Code Here

public class RequiredTranStrategyTest extends AbstractIntegrationTest {
 
  @Test
  public void testRequired() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=Required)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - the user transaction is used to insert a row
      int initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTran", 1);
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and application exception - the user transaction is not rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException());
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
      
      //Test with client transaction and runtime exception - the user transaction is rolled back
      initialRows = bean.countRows();
     
      tran.begin();
      bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException());
      } catch (RuntimeException e) {
          e.printStackTrace();
      }
     
      try {
          tran.commit();
          fail("RollbackException not thrown");
      } catch (RollbackException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //Test without client exception - a container transaction is used to insert the row
      initialRows = bean.countRows();
     
      bean.insertRow("testWithoutClientTran", 1);
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test without client exception and with application exception - the container transaction is not rolled back
      initialRows = bean.countRows();
     
      try {
          bean.insertRow("testWithoutClientTranAndWithAppException", 1, new SQLException("Dummy exception"));
      } catch (Exception e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test without client transaction and with runtime exception - the container transaction is rolled back
      initialRows = bean.countRows();
     
      try {
          bean.insertRow("testWithoutClientTranAndWithRuntimeException", 1, new RuntimeException("Dummy exception"));
      } catch (Exception e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
  }
View Full Code Here

public class RequiresNewTranStrategyTest extends AbstractIntegrationTest {
 
  @Test
  public void testRequiresNew() throws Exception {
      TestBean rnBean = getOsgiService(TestBean.class, "(tranStrategy=RequiresNew)", DEFAULT_TIMEOUT);
      TestBean rBean = getOsgiService(TestBean.class, "(tranStrategy=Required)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - a container transaction is used to insert the row
      int initialRows = rnBean.countRows();
     
      tran.begin();
      rnBean.insertRow("testWithClientTran", 1);
      tran.rollback();
     
      int finalRows = rnBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
     
      //Test with client transaction and application exception - the container transaction is committed,
      //the user transaction is not affected.
      initialRows = rnBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithAppException", 1);
     
      try {
          rnBean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
      } catch (SQLException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      finalRows = rnBean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 2);
     
      //Test with client transaction and runtime exception - the container transaction is rolled back,
      //the user transaction is not affected
      initialRows = rnBean.countRows();
     
      tran.begin();
      rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
     
      try {
          rnBean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
      } catch (RuntimeException e) {
          e.printStackTrace();
View Full Code Here

public class NeverTranStrategyTest extends AbstractIntegrationTest {
 
  @Test
  public void testNever() throws Exception {
      TestBean bean = getOsgiService(TestBean.class, "(tranStrategy=Never)", DEFAULT_TIMEOUT);
      UserTransaction tran = getOsgiService(UserTransaction.class);
     
      //Test with client transaction - an exception is thrown because transactions are not allowed
      int initialRows = bean.countRows();
     
      tran.begin();
     
      try {
          bean.insertRow("testWithClientTran", 1);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
     
      tran.commit();
     
      int finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
     
      //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
      initialRows = bean.countRows();

      try {
          bean.insertRow("testWithoutClientTran", 1, true);
          fail("IllegalStateException not thrown");
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
     
      finalRows = bean.countRows();
      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
  }
View Full Code Here

TOP

Related Classes of org.apache.aries.transaction.test.TestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.