Author: timothyjward
Date: Mon Feb 29 18:52:39 2016
New Revision: 1732931

URL: http://svn.apache.org/viewvc?rev=1732931&view=rev
Log:
[tx-control] Add a Spring JdbcTemplate test

Added:
    
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
      - copied, changed from r1732464, 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
    
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
Modified:
    aries/trunk/tx-control/tx-control-itests/pom.xml
    
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
    
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java

Modified: aries/trunk/tx-control/tx-control-itests/pom.xml
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/pom.xml?rev=1732931&r1=1732930&r2=1732931&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-itests/pom.xml (original)
+++ aries/trunk/tx-control/tx-control-itests/pom.xml Mon Feb 29 18:52:39 2016
@@ -68,11 +68,43 @@
                        <groupId>org.osgi</groupId>
                        <artifactId>org.osgi.service.jdbc</artifactId>
                        <version>1.0.0</version>
+                       <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                        <version>1.4.191</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-jdbc</artifactId>
+                       <version>3.1.4.RELEASE</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-tx</artifactId>
+                       <version>3.1.4.RELEASE</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-beans</artifactId>
+                       <version>3.1.4.RELEASE</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-core</artifactId>
+                       <version>3.1.4.RELEASE</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>spring-context</artifactId>
+                       <version>3.1.4.RELEASE</version>
+                       <scope>test</scope>
                </dependency>
                <dependency>
                        <groupId>org.apache.aries.testsupport</groupId>

Copied: 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
 (from r1732464, 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java?p2=aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java&p1=aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java&r1=1732464&r2=1732931&rev=1732931&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
 Mon Feb 29 18:52:39 2016
@@ -18,19 +18,13 @@
  */
 package org.apache.aries.tx.control.itests;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.CoreOptions.when;
 
-import java.net.URISyntaxException;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Properties;
@@ -40,7 +34,6 @@ import javax.inject.Inject;
 import org.apache.aries.itest.AbstractIntegrationTest;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.CoreOptions;
@@ -49,17 +42,15 @@ 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.osgi.service.jdbc.DataSourceFactory;
-import org.osgi.service.transaction.control.ScopedWorkException;
 import org.osgi.service.transaction.control.TransactionControl;
-import org.osgi.service.transaction.control.TransactionRolledBackException;
 import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
-public class ExceptionManagementTransactionTest extends 
AbstractIntegrationTest {
+public abstract class AbstractTransactionTest extends AbstractIntegrationTest {
 
        @Inject
-       TransactionControl txControl;
+       protected TransactionControl txControl;
 
        @Inject
        JDBCConnectionProviderFactory resourceProviderFactory;
@@ -67,7 +58,7 @@ public class ExceptionManagementTransact
        @Inject
        DataSourceFactory dsf;
        
-       Connection connection;
+       protected Connection connection;
 
        @Before
        public void setUp() {
@@ -83,8 +74,8 @@ public class ExceptionManagementTransact
                                try {
                                        s.execute("DROP TABLE TEST_TABLE");
                                } catch (SQLException sqle) {}
-                                       s.execute("CREATE TABLE TEST_TABLE ( 
message varchar(255) )");
-                                       return null;
+                               s.execute("CREATE TABLE TEST_TABLE ( message 
varchar(255) )");
+                               return null;
                        });
        }
        
@@ -95,113 +86,6 @@ public class ExceptionManagementTransact
                                .execute("DROP TABLE TEST_TABLE"));
 
        }
-       
-       @Test
-       public void testRuntimeException() {
-               
-               RuntimeException toThrow = new RuntimeException("Bang!");
-               
-               try {
-                       txControl.required(() -> {
-                                               connection.createStatement()
-                                                       .execute("Insert into 
TEST_TABLE values ( 'Hello World!' )");
-                                               throw toThrow;
-                                       });
-                       fail("An exception should occur!");
-               } catch (ScopedWorkException swe) {
-                       assertSame(toThrow, swe.getCause());
-               }
-
-               assertRollback();
-       }
-
-       @Test
-       public void testCheckedException() {
-               URISyntaxException toThrow = new URISyntaxException("yuck", 
"Bang!");
-               
-               try {
-                       txControl.required(() -> {
-                                               connection.createStatement()
-                                                       .execute("Insert into 
TEST_TABLE values ( 'Hello World!' )");
-                                               throw toThrow;
-                                       });
-                       fail("An exception should occur!");
-                       // We have to catch Exception as the compiler complains
-                       // otherwise
-               } catch (ScopedWorkException swe) {
-                       assertSame(toThrow, swe.getCause());
-               }
-
-               assertRollback();
-       }
-
-       @Test
-       public void testPreCompletionException() {
-               RuntimeException toThrow = new RuntimeException("Bang!");
-               
-               try {
-                       txControl.required(() -> {
-                               txControl.getCurrentContext().preCompletion(() 
-> {
-                                               throw toThrow;
-                                       });
-                               return connection.createStatement()
-                                       .execute("Insert into TEST_TABLE values 
( 'Hello World!' )");
-                       });
-                       fail("An exception should occur!");
-                       // We have to catch Exception as the compiler complains
-                       // otherwise
-               } catch (TransactionRolledBackException tre) {
-                       assertSame(toThrow, tre.getCause());
-               }
-               
-               assertRollback();
-       }
-
-       @Test
-       public void testNoRollbackForException() {
-               RuntimeException toThrow = new RuntimeException("Bang!");
-               
-               try {
-                       txControl.build()
-                               .noRollbackFor(RuntimeException.class)
-                               .required(() -> {
-                                               PreparedStatement ps = 
connection
-                                                               
.prepareStatement("Insert into TEST_TABLE values ( ? )");
-                                               
-                                               ps.setString(1, "Hello World!");
-                                               ps.executeUpdate();
-                                               
-                                               throw toThrow;
-                                       });
-                       fail("An exception should occur!");
-                       // We have to catch Exception as the compiler complains
-                       // otherwise
-               } catch (ScopedWorkException swe) {
-                       assertSame(toThrow, swe.getCause());
-               }
-               
-               assertEquals("1: Hello World!", txControl.notSupported(() -> {
-                       Statement s = connection.createStatement();
-                       
-                       ResultSet rs = s.executeQuery("Select count(*) from 
TEST_TABLE");
-                       rs.next();
-                       int count = rs.getInt(1);
-                       
-                       rs = s.executeQuery("Select message from TEST_TABLE 
ORDER BY message");
-                       
-                       rs.next();
-                       return "" + count + ": " + rs.getString(1);
-               }));
-       }
-
-       private void assertRollback() {
-               assertEquals(Integer.valueOf(0), txControl.notSupported(() -> {
-                       ResultSet rs = connection.createStatement()
-                                       .executeQuery("Select count(*) from 
TEST_TABLE");
-                       rs.next();
-                       return rs.getInt(1);
-               }));
-       }
 
        @Configuration
        public Option[] configuration() {
@@ -209,14 +93,16 @@ public class ExceptionManagementTransact
                if (localRepo == null) {
                        localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
                }
+               
+               Option testSpecificOptions = testSpecificOptions();
+               
                return options(junitBundles(), 
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
                                when(localRepo != null)
                                                
.useOptions(CoreOptions.vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + 
localRepo)),
                                mavenBundle("org.apache.aries.testsupport", 
"org.apache.aries.testsupport.unit").versionAsInProject(),
-                               mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-local").versionAsInProject(),
-                               mavenBundle("com.h2database", 
"h2").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jdbc-local").versionAsInProject(),
+                               localTxControlService(),
+                               localJdbcResourceProviderWithH2(),
+                               when(testSpecificOptions != 
null).useOptions(testSpecificOptions),
                                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
                                mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
                                
@@ -227,5 +113,20 @@ public class ExceptionManagementTransact
                 */
                );
        }
+       
+       public Option localTxControlService() {
+               return CoreOptions.composite(
+                               mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
+                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-local").versionAsInProject());
+       }
 
+       public Option localJdbcResourceProviderWithH2() {
+               return CoreOptions.composite(
+                               mavenBundle("com.h2database", 
"h2").versionAsInProject(),
+                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jdbc-local").versionAsInProject());
+       }
+
+       protected Option testSpecificOptions() {
+               return null;
+       }
 }

Modified: 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java?rev=1732931&r1=1732930&r2=1732931&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/ExceptionManagementTransactionTest.java
 Mon Feb 29 18:52:39 2016
@@ -21,80 +21,23 @@ package org.apache.aries.tx.control.ites
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.when;
 
 import java.net.URISyntaxException;
-import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
 
-import javax.inject.Inject;
-
-import org.apache.aries.itest.AbstractIntegrationTest;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 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.osgi.service.jdbc.DataSourceFactory;
 import org.osgi.service.transaction.control.ScopedWorkException;
-import org.osgi.service.transaction.control.TransactionControl;
 import org.osgi.service.transaction.control.TransactionRolledBackException;
-import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
-public class ExceptionManagementTransactionTest extends 
AbstractIntegrationTest {
-
-       @Inject
-       TransactionControl txControl;
-
-       @Inject
-       JDBCConnectionProviderFactory resourceProviderFactory;
-       
-       @Inject
-       DataSourceFactory dsf;
-       
-       Connection connection;
-
-       @Before
-       public void setUp() {
-               Properties jdbc = new Properties();
-               
-               jdbc.setProperty(DataSourceFactory.JDBC_URL, 
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
-               
-               connection = resourceProviderFactory.getProviderFor(dsf, jdbc, 
null).getResource(txControl);
-               
-               
-               txControl.required(() -> {
-                               Statement s = connection.createStatement();
-                               try {
-                                       s.execute("DROP TABLE TEST_TABLE");
-                               } catch (SQLException sqle) {}
-                                       s.execute("CREATE TABLE TEST_TABLE ( 
message varchar(255) )");
-                                       return null;
-                       });
-       }
-       
-       @After
-       public void tearDown() {
-
-               txControl.required(() -> connection.createStatement()
-                               .execute("DROP TABLE TEST_TABLE"));
-
-       }
+public class ExceptionManagementTransactionTest extends 
AbstractTransactionTest {
        
        @Test
        public void testRuntimeException() {
@@ -202,30 +145,4 @@ public class ExceptionManagementTransact
                        return rs.getInt(1);
                }));
        }
-
-       @Configuration
-       public Option[] configuration() {
-               String localRepo = System.getProperty("maven.repo.local");
-               if (localRepo == null) {
-                       localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
-               }
-               return options(junitBundles(), 
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
-                               when(localRepo != null)
-                                               
.useOptions(CoreOptions.vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + 
localRepo)),
-                               mavenBundle("org.apache.aries.testsupport", 
"org.apache.aries.testsupport.unit").versionAsInProject(),
-                               mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-local").versionAsInProject(),
-                               mavenBundle("com.h2database", 
"h2").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jdbc-local").versionAsInProject(),
-                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
-                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
-                               
-               /*
-                * vmOption
-                * 
("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
-                * waitForFrameworkStartup(),
-                */
-               );
-       }
-
 }

Modified: 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java?rev=1732931&r1=1732930&r2=1732931&view=diff
==============================================================================
--- 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java
 (original)
+++ 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java
 Mon Feb 29 18:52:39 2016
@@ -19,78 +19,21 @@
 package org.apache.aries.tx.control.itests;
 
 import static org.junit.Assert.assertEquals;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.when;
 
-import java.sql.Connection;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Arrays;
-import java.util.Properties;
 
-import javax.inject.Inject;
-
-import org.apache.aries.itest.AbstractIntegrationTest;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 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.osgi.service.jdbc.DataSourceFactory;
-import org.osgi.service.transaction.control.TransactionControl;
-import org.osgi.service.transaction.control.jdbc.JDBCConnectionProviderFactory;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
-public class SimpleTransactionTest extends AbstractIntegrationTest {
-
-       @Inject
-       TransactionControl txControl;
-
-       @Inject
-       JDBCConnectionProviderFactory resourceProviderFactory;
-       
-       @Inject
-       DataSourceFactory dsf;
-       
-       Connection connection;
-
-       @Before
-       public void setUp() {
-               Properties jdbc = new Properties();
-               
-               jdbc.setProperty(DataSourceFactory.JDBC_URL, 
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
-               
-               connection = resourceProviderFactory.getProviderFor(dsf, jdbc, 
null).getResource(txControl);
-               
-               
-               txControl.required(() -> {
-                               Statement s = connection.createStatement();
-                               try {
-                                       s.execute("DROP TABLE TEST_TABLE");
-                               } catch (SQLException sqle) {}
-                                       s.execute("CREATE TABLE TEST_TABLE ( 
message varchar(255) )");
-                                       return null;
-                       });
-       }
-       
-       @After
-       public void tearDown() {
-
-               txControl.required(() -> connection.createStatement()
-                               .execute("DROP TABLE TEST_TABLE"));
+public class SimpleTransactionTest extends AbstractTransactionTest {
 
-       }
-       
        @Test
        public void testTx() {
                txControl.required(() -> connection.createStatement()
@@ -219,29 +162,5 @@ public class SimpleTransactionTest exten
                                return "" + count + ": " + rs.getString(1);
                        }));
        }
-
-       @Configuration
-       public Option[] configuration() {
-               String localRepo = System.getProperty("maven.repo.local");
-               if (localRepo == null) {
-                       localRepo = 
System.getProperty("org.ops4j.pax.url.mvn.localRepository");
-               }
-               return options(junitBundles(), 
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
-                               when(localRepo != null)
-                                               
.useOptions(CoreOptions.vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + 
localRepo)),
-                               mavenBundle("org.apache.aries.testsupport", 
"org.apache.aries.testsupport.unit").versionAsInProject(),
-                               mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-service-local").versionAsInProject(),
-                               mavenBundle("com.h2database", 
"h2").versionAsInProject(),
-                               mavenBundle("org.apache.aries.tx-control", 
"tx-control-provider-jdbc-local").versionAsInProject(),
-                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-api").versionAsInProject(),
-                               mavenBundle("org.ops4j.pax.logging", 
"pax-logging-service").versionAsInProject()
-               /*
-                * vmOption
-                * 
("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
-                * waitForFrameworkStartup(),
-                */
-               );
-       }
-
+       
 }

Added: 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java?rev=1732931&view=auto
==============================================================================
--- 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
 (added)
+++ 
aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
 Mon Feb 29 18:52:39 2016
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.tx.control.itests;
+
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.StatementCallback;
+import org.springframework.jdbc.datasource.SingleConnectionDataSource;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class SpringJdbcTemplateTransactionTest extends AbstractTransactionTest 
{
+
+       JdbcTemplate jdbcTemplate; 
+
+       @Before
+       public void setUp() {
+               super.setUp();
+               
+               jdbcTemplate = new JdbcTemplate(new 
SingleConnectionDataSource(connection, false));
+       }
+       
+       @Test
+       public void testJdbcTemplateTx() {
+               
+               StatementCallback<Boolean> callback = s -> 
+                       s.execute("Insert into TEST_TABLE values ( 'Hello 
World!' )");
+               
+               txControl.required(() -> jdbcTemplate.execute(callback));
+               
+               assertEquals("Hello World!", txControl.notSupported(() -> 
+                       jdbcTemplate.queryForObject("Select * from TEST_TABLE", 
String.class)));
+       }
+       
+       
+       @Override
+       protected Option testSpecificOptions() {
+               return composite(
+                               mavenBundle("org.springframework", 
"spring-jdbc").versionAsInProject(),
+                               mavenBundle("org.springframework", 
"spring-tx").versionAsInProject(),
+                               mavenBundle("org.springframework", 
"spring-beans").versionAsInProject(),
+                               mavenBundle("org.springframework", 
"spring-core").versionAsInProject(),
+                               mavenBundle("org.springframework", 
"spring-context").versionAsInProject());
+       }
+
+}


Reply via email to