// 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;
/*
   Copyright 2015 Ant Kutschera

   Licensed 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package ch.maxant.generic_jca_adapter;





public class GenericResourceAdapterTest {

	@BeforeClass
	public static void init(){
		for(File f : new File(System.getProperty("java.io.tmpdir")).listFiles()){
			if(f.getName().startsWith("exec") && f.getName().endsWith(".txt")){
				//perhaps its left over from a broken test - be nice to the person running this test :-)
				f.delete();
			}
		}
	}
	
	@Test
	public void testCannotRegisterTwice() {
		
		GenericResourceAdapter adapter = new GenericResourceAdapter();

// 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;

/*
   Copyright 2015 Ant Kutschera

   Licensed 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package ch.maxant.generic_jca_adapter;





public class GenericResourceAdapterTest {

	@BeforeClass
	public static void init(){
		for(File f : new File(System.getProperty("java.io.tmpdir")).listFiles()){
			if(f.getName().startsWith("exec") && f.getName().endsWith(".txt")){
				//perhaps its left over from a broken test - be nice to the person running this test :-)
				f.delete();
			}
		}
	}
	
	@Test
	public void testCannotRegisterTwice() {
		
		GenericResourceAdapter adapter = new GenericResourceAdapter();

		CommitRollbackRecoveryCallback commitRollbackRecoveryCallback = new CommitRollbackRecoveryCallback(){