/*
 * 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());
	}

}

@@ -1025,24 +1025,54 @@
 nBundle;%0D%0A%0D%0A
+import java.sql.ResultSet;%0D%0A%0D%0A
 import org.j
@@ -2221,16 +2221,454 @@
 %0A%09%7D%0D%0A%09%0D%0A
+%09@Test%0D%0A%09public void testJdbcTemplateRollback() %7B%0D%0A%09%09%0D%0A%09%09StatementCallback%3CBoolean%3E callback = s -%3E %0D%0A%09%09%09s.execute(%22Insert into TEST_TABLE values ( 'Hello World!' )%22);%0D%0A%09%09%0D%0A%09%09txControl.required(() -%3E %7B%0D%0A%09%09%09jdbcTemplate.execute(callback);%0D%0A%09%09%09txControl.setRollbackOnly();%0D%0A%09%09%09return null;%0D%0A%09%09%7D);%0D%0A%0D%0A%09%09assertEquals(Integer.valueOf(0), txControl.notSupported(() -%3E %0D%0A%09%09%09jdbcTemplate.queryForInt(%22Select count(*) from TEST_TABLE%22)));%0D%0A%09%7D%0D%0A%09%0D%0A
 %09%0D%0A%09@Ove

Add a Spring rollback test