aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1690232 - in /aries/trunk/transaction: transaction-blueprint/ transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/ transaction-itests/src/test/java/org/apache/aries/transaction/itests/ transaction-testbundle/src/main/j...
Date Fri, 10 Jul 2015 09:34:59 GMT
Author: cschneider
Date: Fri Jul 10 09:34:59 2015
New Revision: 1690232

URL: http://svn.apache.org/r1690232
Log:
[ARIES-628] Refactored tests

Modified:
    aries/trunk/transaction/transaction-blueprint/pom.xml
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
    aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
    aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java

Modified: aries/trunk/transaction/transaction-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/pom.xml?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/pom.xml (original)
+++ aries/trunk/transaction/transaction-blueprint/pom.xml Fri Jul 10 09:34:59 2015
@@ -31,7 +31,7 @@
     <groupId>org.apache.aries.transaction</groupId>
     <artifactId>org.apache.aries.transaction.blueprint</artifactId>
     <packaging>bundle</packaging>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.1.0-SNAPSHOT</version>
     <name>Apache Aries Transaction Blueprint</name>
 
     <scm>

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java (original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/parsing/AnnotationParser.java Fri Jul 10 09:34:59 2015
@@ -87,22 +87,29 @@ public class AnnotationParser implements
 
     private Transaction tryGetTransaction(Method m) {
         Transaction t = m.getAnnotation(Transaction.class);
-        if (t == null) {
-            final Transactional jtaT = m.getAnnotation(Transactional.class);
-            if (jtaT != null) {
-                t = new Transaction() {
-                    @Override
-                    public Class<? extends Annotation> annotationType() {
-                        return Transactional.class;
-                    }
+        if (t != null) {
+            return t;
+        }
+        final Transactional jtaT = m.getAnnotation(Transactional.class);
+        if (jtaT != null) {
+            return toTransaction(jtaT);
+        }
+        return null;
+    }
 
-                    @Override
-                    public TransactionPropagationType value() {
-                        return convert(jtaT.value());
-                    }
-                };
+    private Transaction toTransaction(final Transactional jtaT) {
+        Transaction t;
+        t = new Transaction() {
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return Transactional.class;
             }
-        }
+
+            @Override
+            public TransactionPropagationType value() {
+                return convert(jtaT.value());
+            }
+        };
         return t;
     }
 

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java Fri Jul 10 09:34:59 2015
@@ -18,6 +18,8 @@
  */
 package org.apache.aries.transaction.itests;
 
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
@@ -26,20 +28,27 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.vmOption;
 import static org.ops4j.pax.exam.CoreOptions.when;
 
+import java.sql.SQLException;
+
 import javax.inject.Inject;
+import javax.transaction.RollbackException;
 import javax.transaction.UserTransaction;
 
+import junit.framework.Assert;
+
+import org.apache.aries.transaction.test.TestBean;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.exam.spi.reactors.PerSuite;
 import org.osgi.framework.BundleContext;
 
 @RunWith(PaxExam.class)
-@ExamReactorStrategy(PerSuite.class)
+@ExamReactorStrategy(PerClass.class)
 public abstract class AbstractIntegrationTest {
     @Inject
     BundleContext bundleContext;
@@ -47,6 +56,8 @@ public abstract class AbstractIntegratio
     @Inject
     UserTransaction tran;
 
+    protected boolean clientTransaction = true;
+
     public Option baseOptions() {
         String localRepo = System.getProperty("maven.repo.local");
         if (localRepo == null) {
@@ -104,4 +115,112 @@ public abstract class AbstractIntegratio
             );
     }
 
+    // Test with client transaction and runtime exception - the user transaction is rolled back
+    protected void assertInsertWithRuntimeExceptionRolledBack() throws Exception {
+        TestBean bean = getBean();
+        int initialRows = bean.countRows();
+
+        if (clientTransaction) {
+            tran.begin();
+        }
+        bean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+        try {
+            bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
+        } catch (RuntimeException e) {
+            Assert.assertEquals("Dummy exception", e.getMessage());
+        }
+        if (clientTransaction) {
+            try {
+                tran.commit();
+                fail("RollbackException not thrown");
+            } catch (RollbackException e) {
+                // Ignore expected
+            }
+        }
+
+        int finalRows = bean.countRows();
+        // In case of client transaction both are rolled back
+        // In case of container transaction only second insert is rolled back
+        assertEquals("Added rows", clientTransaction ? 0 : 1, finalRows - initialRows);
+    }
+
+    protected void assertInsertWithAppExceptionCommitted() throws Exception {
+        TestBean bean = getBean();
+        int initialRows = bean.countRows();
+        if (clientTransaction) {
+            tran.begin();
+        }
+        bean.insertRow("testWithClientTranAndWithAppException", 1);
+        try {
+            bean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
+        } catch (SQLException e) {
+            Assert.assertEquals("Dummy exception", e.getMessage());
+        }
+        if (clientTransaction) {
+            tran.commit();
+        }
+
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 2, finalRows - initialRows);
+    }
+
+    protected void assertInsertSuccesful() throws Exception {
+        TestBean bean = getBean();
+        int initialRows = bean.countRows();
+
+        if (clientTransaction ) {
+            tran.begin();
+        }
+        bean.insertRow("testWithClientTran", 1);
+        if (clientTransaction ) {
+            tran.commit();
+        }
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 1, finalRows - initialRows);
+    }
+
+    // Test with client transaction - an exception is thrown because transactions are not allowed
+    protected void assertInsertWithTranFails() throws Exception {
+        TestBean bean = getBean();
+        int initialRows = bean.countRows();
+        tran.begin();
+        try {
+            bean.insertRow("testWithClientTran", 1);
+            fail("IllegalStateException not thrown");
+        } catch (IllegalStateException e) {
+            // Ignore Expected
+        }
+        tran.commit();
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 0, finalRows - initialRows);
+    }
+    
+    // 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 assertDelegatedInsertWithoutTranFails() throws SQLException {
+        TestBean bean = getBean();
+        int initialRows = bean.countRows();
+
+        try {
+            bean.insertRow("testWithoutClientTran", 1, true);
+            fail("IllegalStateException not thrown");
+        } catch (IllegalStateException e) {
+            // Ignore expected
+        }
+
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 0, finalRows - initialRows);
+    }
+
+    // Test without client transaction - an exception is thrown because a transaction is mandatory
+    protected void assertMandatoryTransaction() throws SQLException {
+          try {
+              getBean().insertRow("testWithoutClientTran", 1);
+              fail("IllegalStateException not thrown");
+          } catch (IllegalStateException e) {
+              // Ignore expected
+          }
+    }
+    
+    protected abstract TestBean getBean();
 }
\ No newline at end of file

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/InvalidTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -22,11 +22,17 @@ import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class InvalidTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=MandatoryJtaAnnotated)") 
+    @Inject
+    @Filter("(tranAttribute=MandatoryJtaAnnotated)")
     TestBean bean;
-    
-  @Test(expected=IllegalStateException.class)
-  public void testInvalid() throws Exception {
-      bean.insertRow("testWithoutClientTran", 1);
-  }
+
+    @Test(expected = IllegalStateException.class)
+    public void testInvalid() throws Exception {
+        bean.insertRow("testWithoutClientTran", 1);
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryAnnotatedTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,80 +15,27 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.sql.SQLException;
-
 import javax.inject.Inject;
-import javax.transaction.RollbackException;
 
 import org.apache.aries.transaction.test.TestBean;
 import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class MandatoryAnnotatedTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=MandatoryAnnotated)") 
+    @Inject
+    @Filter("(tranAttribute=MandatoryAnnotated)")
     TestBean bean;
-  
-  @Test
-  public void testMandatory() throws Exception {
-      String prefix = "MTAT";
-      //Test with client transaction - the user transaction is used to insert a row
-      int initialRows = bean.countRows();
-      
-      tran.begin();
-      bean.insertRow(prefix + "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(prefix + "testWithClientTranAndWithAppException", 1);
-      
-      try {
-          bean.insertRow(prefix + "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(prefix + "testWithClientTranAndWithRuntimeException", 1);
-      
-      try {
-          bean.insertRow(prefix + "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(prefix + "testWithoutClientTran", 1);
-          fail("IllegalStateException not thrown");
-      } catch (IllegalStateException e) {
-          e.printStackTrace();
-      }
-  }
+
+    @Test
+    public void testMandatory() throws Exception {
+        assertInsertSuccesful();
+        assertInsertWithAppExceptionCommitted();
+        assertInsertWithRuntimeExceptionRolledBack();
+        assertMandatoryTransaction();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryJtaAnnotatedTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,81 +15,28 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.sql.SQLException;
-
 import javax.inject.Inject;
-import javax.transaction.RollbackException;
 
 import org.apache.aries.transaction.test.TestBean;
 import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class MandatoryJtaAnnotatedTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=MandatoryJtaAnnotated)") 
+    @Inject
+    @Filter("(tranAttribute=MandatoryJtaAnnotated)")
     TestBean bean;
-  
-  @Test
-  public void testMandatory() throws Exception {
-      String prefix = "MTAT";
-      
-      //Test with client transaction - the user transaction is used to insert a row
-      int initialRows = bean.countRows();
-      
-      tran.begin();
-      bean.insertRow(prefix + "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(prefix + "testWithClientTranAndWithAppException", 1);
-      
-      try {
-          bean.insertRow(prefix + "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(prefix + "testWithClientTranAndWithRuntimeException", 1);
-      
-      try {
-          bean.insertRow(prefix + "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(prefix + "testWithoutClientTran", 1);
-          fail("IllegalStateException not thrown");
-      } catch (IllegalStateException e) {
-          e.printStackTrace();
-      }
-  }
+
+    @Test
+    public void testMandatory() throws Exception {
+        assertInsertSuccesful();
+        assertInsertWithAppExceptionCommitted();
+        assertInsertWithRuntimeExceptionRolledBack();
+        assertMandatoryTransaction();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
+
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/MandatoryTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,83 +15,29 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.sql.SQLException;
-
 import javax.inject.Inject;
-import javax.transaction.RollbackException;
-
-import junit.framework.Assert;
 
 import org.apache.aries.transaction.test.TestBean;
 import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class MandatoryTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=Mandatory)") 
+    @Inject
+    @Filter("(tranAttribute=Mandatory)")
     TestBean bean;
-  
-  @Test
-  public void testMandatory() throws Exception {
-      String prefix = "MTAT";
-      
-      //Test with client transaction - the user transaction is used to insert a row
-      int initialRows = bean.countRows();
-      
-      tran.begin();
-      bean.insertRow(prefix + "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(prefix + "testWithClientTranAndWithAppException", 1);
-      
-      try {
-        bean.insertRow(prefix + "testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
-      } catch (SQLException e) {
-        Assert.assertEquals("Dummy exception", e.getMessage());
-      }
-      
-      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(prefix + "testWithClientTranAndWithRuntimeException", 1);
-      
-      try {
-          bean.insertRow(prefix + "testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
-      } catch (RuntimeException e) {
-          Assert.assertEquals("Dummy exception", e.getMessage());
-        }
-      
-      try {
-          tran.commit();
-          fail("RollbackException not thrown");
-      } catch (RollbackException e) {
-          // Ignore expected
-      }
-      
-      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(prefix + "testWithoutClientTran", 1);
-          fail("IllegalStateException not thrown");
-      } catch (IllegalStateException e) {
-          e.printStackTrace();
-      }
-  }
+
+    @Test
+    public void testMandatory() throws Exception {
+        assertInsertSuccesful();
+        assertInsertWithAppExceptionCommitted();
+        assertInsertWithRuntimeExceptionRolledBack();
+        assertMandatoryTransaction();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
+
+
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NeverTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,9 +15,6 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import javax.inject.Inject;
 
 import org.apache.aries.transaction.test.TestBean;
@@ -25,41 +22,19 @@ import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class NeverTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=Never)") 
+    @Inject
+    @Filter("(tranAttribute=Never)")
     TestBean bean;
-  
-  @Test
-  public void testNever() throws Exception {
-      //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);
-  }
-  
+
+    @Test
+    public void testNever() throws Exception {
+        assertInsertWithTranFails();
+        assertDelegatedInsertWithoutTranFails();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
+
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/NotSupportedTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -47,7 +47,7 @@ public class NotSupportedTranAttributeTe
           nsBean.insertRow("testWithClientTran", 1, true);
           fail("IllegalStateException not thrown");
       } catch (IllegalStateException e) {
-          e.printStackTrace();
+          // Ignore expected
       }
       
       tran.commit();
@@ -65,7 +65,7 @@ public class NotSupportedTranAttributeTe
       try {
           nsBean.throwApplicationException();
       } catch (SQLException e) {
-          e.printStackTrace();
+          // Ignore expected
       }
       
       tran.commit();
@@ -83,7 +83,7 @@ public class NotSupportedTranAttributeTe
       try {
           nsBean.throwRuntimeException();
       } catch (RuntimeException e) {
-          e.printStackTrace();
+          // Ignore expected
       }
       
       tran.commit();
@@ -99,10 +99,16 @@ public class NotSupportedTranAttributeTe
           nsBean.insertRow("testWithoutClientTran", 1, true);
           fail("IllegalStateException not thrown");
       } catch (IllegalStateException e) {
-          e.printStackTrace();
+          // Ignore expected
       }
       
       finalRows = nsBean.countRows();
       assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
   }
+
+    @Override
+    protected TestBean getBean() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiredTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,103 +15,27 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.sql.SQLException;
-
 import javax.inject.Inject;
-import javax.transaction.RollbackException;
 
 import org.apache.aries.transaction.test.TestBean;
 import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class RequiredTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=Required)") 
+    @Inject
+    @Filter("(tranAttribute=Required)")
     TestBean bean;
-  
-  @Test
-  public void testRequired() throws Exception {
-      //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);
-  }
+
+    @Test
+    public void testRequired() throws Exception {
+        clientTransaction = false;
+        assertInsertSuccesful();
+        assertInsertWithAppExceptionCommitted();
+        assertInsertWithRuntimeExceptionRolledBack();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/RequiresNewTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,7 +15,7 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
+import static junit.framework.Assert.assertEquals;
 
 import java.sql.SQLException;
 
@@ -26,91 +26,84 @@ import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class RequiresNewTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=RequiresNew)") 
+    @Inject
+    @Filter("(tranAttribute=RequiresNew)")
     TestBean rnBean;
-    
-    @Inject @Filter("(tranAttribute=Required)") 
+
+    @Inject
+    @Filter("(tranAttribute=Required)")
     TestBean rBean;
 
+    /**
+     * Test with client transaction - a container transaction is used to insert the row,
+     * user transaction roll back has no influence
+     * @throws Exception
+     */
+    @Test
+    public void testClientTransactionRollback() throws Exception {
+        int initialRows = rnBean.countRows();
+        tran.begin();
+        rnBean.insertRow("testWithClientTran", 1);
+        tran.rollback();
+        int finalRows = rnBean.countRows();
+        assertEquals("Added rows", 1, finalRows - initialRows);
+    }
+    
+    /**
+     * Test with client transaction and application exception - the container transaction is committed,
+     * the user transaction is not affected.
+     * @throws Exception
+     */
+    @Test
+    public void testClientTransactionAndApplicationException() throws Exception {
+        int initialRows = rnBean.countRows();
+        tran.begin();
+        rBean.insertRow("testWithClientTranAndWithAppException", 1);
+        try {
+            rnBean.insertRow("testWithClientTranAndWithAppException", 2, new SQLException("Dummy exception"));
+        } catch (SQLException e) {
+            // Ignore expected
+        }
+        tran.commit();
+        int finalRows = rnBean.countRows();
+        assertEquals("Added rows", 2, finalRows - initialRows);
+
+    }
+
+    /**
+     * Test with client transaction and runtime exception - the container transaction is rolled back,
+     * the user transaction is not affected
+     * @throws Exception
+     */
+    @Test
+    public void testClientTransactionAndRuntimeException() throws Exception {
+        int initialRows = rnBean.countRows();
+        tran.begin();
+        rBean.insertRow("testWithClientTranAndWithRuntimeException", 1);
+        try {
+            rnBean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
+        } catch (RuntimeException e) {
+         // Ignore expected
+        }
+        tran.commit();
+        int finalRows = rnBean.countRows();
+        assertEquals("Added rows", 1, finalRows - initialRows);
+    }
     
-  @Test
-  public void testRequiresNew() throws Exception {
-      //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();
-      }
-      
-      tran.commit();
-      
-      finalRows = rnBean.countRows();
-      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
-      
-      //Test without client transaction - a container transaction is used to insert the row
-      initialRows = rnBean.countRows();
-      
-      rnBean.insertRow("testWithoutClientTran", 1);
-      
-      finalRows = rnBean.countRows();
-      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 1);
-      
-      //Test without client transaction and with application exception - the container transaction is committed
-      initialRows = rnBean.countRows();
-      
-      try {
-          rnBean.insertRow("testWithoutClientTranAndWithAppException", 1, new SQLException("Dummy exception"));
-      } catch (Exception e) {
-          e.printStackTrace();
-      }
-      
-      finalRows = rnBean.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 = rnBean.countRows();
-      
-      try {
-          rnBean.insertRow("testWithoutClientTranAndWithRuntimeException", 1, new RuntimeException("Dummy exception"));
-      } catch (Exception e) {
-          e.printStackTrace();
-      }
-      
-      finalRows = rnBean.countRows();
-      assertTrue("Initial rows: " + initialRows + ", Final rows: " + finalRows, finalRows - initialRows == 0);
-  }
+    /**
+     * Test without client transaction - a container transaction is used to insert the row
+     * @throws Exception
+     */
+    //@Test
+    public void testNoClientTransaction() throws Exception {
+        clientTransaction = false;
+        assertInsertSuccesful();
+        testClientTransactionAndApplicationException();
+        testClientTransactionAndRuntimeException();
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return rnBean;
+    }
 }

Modified: aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java (original)
+++ aries/trunk/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/SupportsTranAttributeTest.java Fri Jul 10 09:34:59 2015
@@ -15,88 +15,76 @@
  */
 package org.apache.aries.transaction.itests;
 
-import static org.junit.Assert.assertTrue;
+import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-import java.sql.SQLException;
-
 import javax.inject.Inject;
-import javax.transaction.RollbackException;
 
 import org.apache.aries.transaction.test.TestBean;
 import org.junit.Test;
 import org.ops4j.pax.exam.util.Filter;
 
 public class SupportsTranAttributeTest extends AbstractIntegrationTest {
-    @Inject @Filter("(tranAttribute=Supports)") 
+    @Inject
+    @Filter("(tranAttribute=Supports)")
     TestBean bean;
-  
-  @Test
-  public void testSupports() throws Exception {
-      //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);
-  }
+
+    /**
+     * 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
+     * @throws Exception
+     */
+    @Test
+    public void testDelegatedInsertWithClientTransaction() throws Exception {
+        int initialRows = bean.countRows();
+
+        tran.begin();
+        bean.insertRow("testWithClientTran", 1, true);
+        tran.commit();
+
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 1, finalRows - initialRows);
+    }
+    
+    /**
+     * Test with client transaction and application exception - the user transaction is not rolled back
+     * @throws Exception
+     */
+    @Test
+    public void testInsertWithAppExceptionCommitted() throws Exception {
+        assertInsertWithAppExceptionCommitted();
+    }
+    
+    /**
+     * Test with client transaction and runtime exception - the user transaction is rolled back
+     * @throws Exception
+     */
+    @Test
+    public void testInsertWithRuntimeExceptionRolledBack() throws Exception {
+        assertInsertWithRuntimeExceptionRolledBack();
+    }
+    
+    /**
+     * 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
+     * @throws Exception
+     */
+    @Test
+    public void testDelegatedWithoutClientTransactionFails() throws Exception {
+        int initialRows = bean.countRows();
+        try {
+            bean.insertRow("testWithoutClientTran", 1, true);
+            fail("Exception not thrown");
+        } catch (Exception e) {
+            // Ignore expected
+        }
+        int finalRows = bean.countRows();
+        assertEquals("Added rows", 0, finalRows - initialRows);
+    }
+
+    @Override
+    protected TestBean getBean() {
+        return bean;
+    }
 }

Modified: aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java?rev=1690232&r1=1690231&r2=1690232&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java (original)
+++ aries/trunk/transaction/transaction-testbundle/src/main/java/org/apache/aries/transaction/test/impl/TestBeanImpl.java Fri Jul 10 09:34:59 2015
@@ -30,13 +30,9 @@ import org.apache.aries.transaction.test
 
 public class TestBeanImpl implements TestBean {
     private DataSource xads;
-
     private DataSource ds;
-
     private String user;
-
     private String password;
-    
     private TestBean bean;
 
     public TestBeanImpl() {
@@ -53,24 +49,11 @@ public class TestBeanImpl implements Tes
             stmt.executeUpdate("DROP TABLE TESTTABLE");
         }
         catch (Exception e) {
-            e.printStackTrace();
+            // Ignore
         }
         finally {
-            try {
-                if (stmt != null)
-                    stmt.close();
-            } catch (SQLException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-
-            try {
-                if (conn != null)
-                    conn.close();
-            } catch (SQLException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
+            safeClose(stmt);
+            safeClose(conn);
         }
 
         try {
@@ -80,27 +63,16 @@ public class TestBeanImpl implements Tes
             stmt.executeUpdate("CREATE TABLE TESTTABLE (NAME VARCHAR(64), VALUE INTEGER, PRIMARY KEY(NAME, VALUE))");
         }
         catch (Exception e) {
-            e.printStackTrace();
+            // Ignore
         }
         finally {
-            try {
-                if (stmt != null)
-                    stmt.close();
-            } catch (SQLException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
-
-            try {
-                if (conn != null)
-                    conn.close();
-            } catch (SQLException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            }
+            safeClose(stmt);
+            safeClose(conn);
         }
     }
 
+
+
     public void insertRow(String name, int value) throws SQLException {
         insertRow(name, value, false);
     }
@@ -130,11 +102,8 @@ public class TestBeanImpl implements Tes
                 stmt.executeUpdate();
             }
             finally {
-                if (stmt != null)
-                    stmt.close();
-
-                if (conn != null)
-                    conn.close();
+                safeClose(stmt);
+                safeClose(conn);
             }
         }
     }
@@ -155,12 +124,8 @@ public class TestBeanImpl implements Tes
         finally {
             if (rs != null)
                 rs.close();
-
-            if (stmt != null)
-                stmt.close();
-
-            if (conn != null)
-                conn.close();
+            safeClose(stmt);
+            safeClose(conn);
         }
 
         return count;
@@ -193,4 +158,26 @@ public class TestBeanImpl implements Tes
     public void setTestBean(TestBean bean) {
         this.bean = bean;
     }
+    
+    private void safeClose(Connection conn) {
+        if (conn == null) {
+            return;
+        }
+        try {
+            conn.close();
+        } catch (SQLException e) {
+            // Ignore
+        }
+    }
+
+    private void safeClose(Statement stmt) {
+        if (stmt == null) {
+            return;
+        }
+        try {
+            stmt.close();
+        } catch (SQLException e) {
+            // Ignore
+        }
+    }
 }



Mime
View raw message