// Path: connector/genericconnector-impl/src/test/java/ch/maxant/generic_jca_adapter/MiniContainer.java
// public static class Transaction {
// 	private TransactionState transactionState = TransactionState.RUNNING;
// 	private ArrayList<XAResource> xaResources = new ArrayList<XAResource>();
// 	private Xid xid = new XidImpl("gtid".getBytes(), transactionNumber.getAndIncrement(), "bq".getBytes());
// 	private boolean shouldRollback;
// 	public List<Exception> exceptions = new ArrayList<Exception>();
// 		
// 	public TransactionState getTransactionState() {
// 		return transactionState;
// 	}
// 	public boolean isShouldRollback() {
// 		return shouldRollback;
// 	}
// 	public String getTxid() {
// 		return XidImpl.asString(xid);
// 	}
// 	public List<Exception> getExceptions() {
// 		return exceptions;
// 	}
// }
// 
// Path: connector/genericconnector-impl/src/test/java/ch/maxant/generic_jca_adapter/MiniContainer.java
// public static enum TransactionState {
// 	RUNNING, PREPARING, COMMITTING, ROLLINGBACK;
// }
// 
// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionAssistanceFactory.java
// public static interface CommitRollbackRecoveryCallback extends CommitRollbackCallback {
//         
//     /** The container will call this function during
//      * recovery which should call the EIS and must return 
//      * transaction IDs which are known to be incomplete (not 
//      * yet committed or rolled back). Note that if the 
//      * Resource Adapter is configured to manage transaction
//      * state internally, then this method will not
//      * be called and can have an empty implementation. */
//     String[] getTransactionsInNeedOfRecovery();
// 
//     /** Builder enabling use of Java 8 SAMs */ 
//     public static class Builder {
//         private CommitRollbackFunction commit;
//         private CommitRollbackFunction rollback;
//         private RecoveryFunction recovery;
//         public Builder withCommit(CommitRollbackFunction commit){
//             this.commit = commit;
//             return this;
//         }
//         public Builder withRollback(CommitRollbackFunction rollback){
//             this.rollback = rollback;
//             return this;
//         }
//         public Builder withRecovery(RecoveryFunction recovery){
//             this.recovery = recovery;
//             return this;
//         }
//         public CommitRollbackRecoveryCallback build(){
//             Objects.requireNonNull(commit, "Please call withCommit(...)");
//             Objects.requireNonNull(rollback, "Please call withRollback(...)");
//             //recovery is optional, since you can configure adapter to handle state internally
//                 
//             return new CommitRollbackRecoveryCallback(){
// 	private static final long serialVersionUID = 1L;
// 	@Override
//                 public void commit(String txid) throws Exception {
//                     commit.apply(txid);
//                 }
//                 @Override
//                 public void rollback(String txid) throws Exception {
//                     rollback.apply(txid);
//                 }
//                 @Override
//                 public String[] getTransactionsInNeedOfRecovery() {
//                     if(recovery == null){
//                         return new String[0];
//                     }else{
//                         return recovery.getTransactionsInNeedOfRecovery();
//                     }
//                 }
//             };
//         }
//             
//         public static interface RecoveryFunction {
//             String[] getTransactionsInNeedOfRecovery();
//         }
//             
//         public static interface CommitRollbackFunction {
//             void apply(String txid) throws Exception;
//         }
//     }
// }


import org.junit.Test;
import ch.maxant.generic_jca_adapter.MiniContainer.Transaction;
import ch.maxant.generic_jca_adapter.MiniContainer.TransactionState;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.BeforeClass;
	}
	
	@Test
	public void testInContainer_CommitFailureHandledLaterInRecovery() throws Exception {
		MiniContainer container = new MiniContainer();

		//injection
		TransactionAssistanceFactory bookingFactory = container.lookupAdapter();

		//setup commit/rollback caller
		final AtomicInteger commitCalled = new AtomicInteger();
		final AtomicInteger rollbackCalled = new AtomicInteger();
		final AtomicInteger recoveryCalled = new AtomicInteger();

		registerCallbacks(bookingFactory, commitCalled, rollbackCalled, recoveryCalled, null, true);

		//method start
		final Transaction tx = container.startTransaction();
	    
		//business code
    	TransactionAssistant bookingTransactionAssistant = bookingFactory.getTransactionAssistant();
        String bookingResponse = bookingTransactionAssistant.executeInActiveTransaction(new ExecuteCallback<String>() {
        	@Override
        	public String execute(String txid) throws Exception {
        		return "1";
        	}
		});
        bookingTransactionAssistant.close();

        //method exit
// Path: connector/genericconnector-impl/src/test/java/ch/maxant/generic_jca_adapter/MiniContainer.java
// public static class Transaction {
// 	private TransactionState transactionState = TransactionState.RUNNING;
// 	private ArrayList<XAResource> xaResources = new ArrayList<XAResource>();
// 	private Xid xid = new XidImpl("gtid".getBytes(), transactionNumber.getAndIncrement(), "bq".getBytes());
// 	private boolean shouldRollback;
// 	public List<Exception> exceptions = new ArrayList<Exception>();
// 		
// 	public TransactionState getTransactionState() {
// 		return transactionState;
// 	}
// 	public boolean isShouldRollback() {
// 		return shouldRollback;
// 	}
// 	public String getTxid() {
// 		return XidImpl.asString(xid);
// 	}
// 	public List<Exception> getExceptions() {
// 		return exceptions;
// 	}
// }
// 
// Path: connector/genericconnector-impl/src/test/java/ch/maxant/generic_jca_adapter/MiniContainer.java
// public static enum TransactionState {
// 	RUNNING, PREPARING, COMMITTING, ROLLINGBACK;
// }
// 
// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionAssistanceFactory.java
// public static interface CommitRollbackRecoveryCallback extends CommitRollbackCallback {
//         
//     /** The container will call this function during
//      * recovery which should call the EIS and must return 
//      * transaction IDs which are known to be incomplete (not 
//      * yet committed or rolled back). Note that if the 
//      * Resource Adapter is configured to manage transaction
//      * state internally, then this method will not
//      * be called and can have an empty implementation. */
//     String[] getTransactionsInNeedOfRecovery();
// 
//     /** Builder enabling use of Java 8 SAMs */ 
//     public static class Builder {
//         private CommitRollbackFunction commit;
//         private CommitRollbackFunction rollback;
//         private RecoveryFunction recovery;
//         public Builder withCommit(CommitRollbackFunction commit){
//             this.commit = commit;
//             return this;
//         }
//         public Builder withRollback(CommitRollbackFunction rollback){
//             this.rollback = rollback;
//             return this;
//         }
//         public Builder withRecovery(RecoveryFunction recovery){
//             this.recovery = recovery;
//             return this;
//         }
//         public CommitRollbackRecoveryCallback build(){
//             Objects.requireNonNull(commit, "Please call withCommit(...)");
//             Objects.requireNonNull(rollback, "Please call withRollback(...)");
//             //recovery is optional, since you can configure adapter to handle state internally
//                 
//             return new CommitRollbackRecoveryCallback(){
// 	private static final long serialVersionUID = 1L;
// 	@Override
//                 public void commit(String txid) throws Exception {
//                     commit.apply(txid);
//                 }
//                 @Override
//                 public void rollback(String txid) throws Exception {
//                     rollback.apply(txid);
//                 }
//                 @Override
//                 public String[] getTransactionsInNeedOfRecovery() {
//                     if(recovery == null){
//                         return new String[0];
//                     }else{
//                         return recovery.getTransactionsInNeedOfRecovery();
//                     }
//                 }
//             };
//         }
//             
//         public static interface RecoveryFunction {
//             String[] getTransactionsInNeedOfRecovery();
//         }
//             
//         public static interface CommitRollbackFunction {
//             void apply(String txid) throws Exception;
//         }
//     }
// }


// Path: connector/genericconnector-impl/src/test/java/ch/maxant/generic_jca_adapter/GenericResourceAdapterTest.java
import org.junit.Test;
import ch.maxant.generic_jca_adapter.MiniContainer.Transaction;
import ch.maxant.generic_jca_adapter.MiniContainer.TransactionState;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.BeforeClass;

	}
	
	@Test
	public void testInContainer_CommitFailureHandledLaterInRecovery() throws Exception {
		MiniContainer container = new MiniContainer();

		//injection
		TransactionAssistanceFactory bookingFactory = container.lookupAdapter();

		//setup commit/rollback caller
		final AtomicInteger commitCalled = new AtomicInteger();
		final AtomicInteger rollbackCalled = new AtomicInteger();
		final AtomicInteger recoveryCalled = new AtomicInteger();

		registerCallbacks(bookingFactory, commitCalled, rollbackCalled, recoveryCalled, null, true);

		//method start
		final Transaction tx = container.startTransaction();
	    
		//business code
    	TransactionAssistant bookingTransactionAssistant = bookingFactory.getTransactionAssistant();
        String bookingResponse = bookingTransactionAssistant.executeInActiveTransaction(new ExecuteCallback<String>() {
        	@Override
        	public String execute(String txid) throws Exception {
        		return "1";
        	}
		});
        bookingTransactionAssistant.close();

        //method exit
        container.finishTransaction();