// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/datasource/lookup/IsolationLevelContentSourceRouter.java
// public class IsolationLevelContentSourceRouter extends AbstractRoutingContentSource {
// 
//     /** Constants instance for TransactionDefinition */
//     private static final Constants constants = new Constants(TransactionDefinition.class);
// 
// 
//     /**
//      * Supports Integer values for the isolation level constants
//      * as well as isolation level names as defined on the
//      * {@link TransactionDefinition TransactionDefinition interface}.
//      */
//     @Override
//     protected Object resolveSpecifiedLookupKey(Object lookupKey) {
//         if (lookupKey instanceof Integer) {
//             return lookupKey;
//         } else if (lookupKey instanceof String) {
//             String constantName = (String) lookupKey;
//             if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) {
//                 throw new IllegalArgumentException("Only isolation constants allowed");
//             }
//             return constants.asNumber(constantName);
//         } else {
//             throw new IllegalArgumentException(
//                     "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey);
//         }
//     }
// 
//     @Override
//     @Nullable
//     protected Object determineCurrentLookupKey() {
//         return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
//     }
// 
// }


import com._4dconcept.springframework.data.marklogic.datasource.lookup.IsolationLevelContentSourceRouter;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.Session;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.jta.JtaTransactionObject;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.atLeastOnce;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
            protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
                Session c = ContentSourceUtils.getSession(dsToUse);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                assertSame(session, c);
                ContentSourceUtils.releaseSession(c, dsToUse);
            }
        });

        verify(userTransaction, times(2)).begin();
        verify(userTransaction, times(2)).commit();
        verify(session).setTransactionMode(Session.TransactionMode.QUERY);
        verify(session, times(2)).close();
    }

    @Test
    public void testJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
        doTestJtaTransactionWithIsolationLevelContentSourceRouter();
    }

    private void doTestJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
        given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);

        final ContentSource contentSource1 = mock(ContentSource.class);
        final Session session1 = mock(Session.class);
        given(contentSource1.newSession()).willReturn(session1);

        final ContentSource contentSource2 = mock(ContentSource.class);
        final Session session2 = mock(Session.class);
        given(contentSource2.newSession()).willReturn(session2);

// Path: src/main/java/com/_4dconcept/springframework/data/marklogic/datasource/lookup/IsolationLevelContentSourceRouter.java
// public class IsolationLevelContentSourceRouter extends AbstractRoutingContentSource {
// 
//     /** Constants instance for TransactionDefinition */
//     private static final Constants constants = new Constants(TransactionDefinition.class);
// 
// 
//     /**
//      * Supports Integer values for the isolation level constants
//      * as well as isolation level names as defined on the
//      * {@link TransactionDefinition TransactionDefinition interface}.
//      */
//     @Override
//     protected Object resolveSpecifiedLookupKey(Object lookupKey) {
//         if (lookupKey instanceof Integer) {
//             return lookupKey;
//         } else if (lookupKey instanceof String) {
//             String constantName = (String) lookupKey;
//             if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) {
//                 throw new IllegalArgumentException("Only isolation constants allowed");
//             }
//             return constants.asNumber(constantName);
//         } else {
//             throw new IllegalArgumentException(
//                     "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey);
//         }
//     }
// 
//     @Override
//     @Nullable
//     protected Object determineCurrentLookupKey() {
//         return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
//     }
// 
// }


// Path: src/test/java/com/_4dconcept/springframework/data/marklogic/datasource/DatabaseConnectorJtaTransactionTest.java
import com._4dconcept.springframework.data.marklogic.datasource.lookup.IsolationLevelContentSourceRouter;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.Session;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.jta.JtaTransactionObject;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.atLeastOnce;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

            protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
                Session c = ContentSourceUtils.getSession(dsToUse);
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(dsToUse));
                assertSame(session, c);
                ContentSourceUtils.releaseSession(c, dsToUse);
            }
        });

        verify(userTransaction, times(2)).begin();
        verify(userTransaction, times(2)).commit();
        verify(session).setTransactionMode(Session.TransactionMode.QUERY);
        verify(session, times(2)).close();
    }

    @Test
    public void testJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
        doTestJtaTransactionWithIsolationLevelContentSourceRouter();
    }

    private void doTestJtaTransactionWithIsolationLevelContentSourceRouter() throws Exception {
        given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE, Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);

        final ContentSource contentSource1 = mock(ContentSource.class);
        final Session session1 = mock(Session.class);
        given(contentSource1.newSession()).willReturn(session1);

        final ContentSource contentSource2 = mock(ContentSource.class);
        final Session session2 = mock(Session.class);
        given(contentSource2.newSession()).willReturn(session2);

        final IsolationLevelContentSourceRouter dsToUse = new IsolationLevelContentSourceRouter();