geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/connectiontracking ConnectionTrackingCoordinatorTest.java
Date Tue, 09 Dec 2003 04:17:39 GMT
djencks     2003/12/08 20:17:39

  Added:       modules/core/src/test/org/apache/geronimo/connector/outbound
                        ConnectionTrackingInterceptorTest.java
                        LocalXAResourceInsertionInterceptorTest.java
                        SubjectInterceptorTest.java
                        TransactionCachingInterceptorTest.java
                        TransactionEnlistingInterceptorTest.java
                        XAResourceInsertionInterceptorTest.java
               modules/core/src/test/org/apache/geronimo/connector/outbound/connectiontracking
                        ConnectionTrackingCoordinatorTest.java
  Log:
  tests for many connection framework interceptors
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/ConnectionTrackingInterceptorTest.java
  
  Index: ConnectionTrackingInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import java.util.HashSet;
  import java.util.Collection;
  import java.util.Set;
  import java.security.Principal;
  import java.io.PrintWriter;
  
  import javax.resource.ResourceException;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.ConnectionEventListener;
  import javax.resource.spi.LocalTransaction;
  import javax.resource.spi.ManagedConnectionMetaData;
  import javax.resource.spi.DissociatableManagedConnection;
  import javax.security.auth.Subject;
  import javax.transaction.xa.XAResource;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
  
  /**
   * TODO test unshareable resources.
   * TODO test repeat calls with null/non-null Subject
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class ConnectionTrackingInterceptorTest extends TestCase
      implements ConnectionTracker, ConnectionInterceptor, SecurityDomain {
  
      private final static String key = "test-name";
      private ConnectionTrackingInterceptor connectionTrackingInterceptor;
  
      private Subject subject;
  
      private ConnectionTrackingInterceptor obtainedConnectionTrackingInterceptor;
      private ConnectionInfo obtainedConnectionInfo;
  
      private ConnectionTrackingInterceptor releasedConnectionTrackingInterceptor;
      private ConnectionInfo releasedConnectionInfo;
      private boolean gotConnection;
      private boolean returnedConnection;
  
      private Collection connectionInfos;
      private Set unshareable;
  
      private ManagedConnection managedConnection;
  
      protected void setUp() throws Exception {
          connectionTrackingInterceptor = new ConnectionTrackingInterceptor(this, key, this, this);
      }
  
      protected void tearDown() throws Exception {
          connectionTrackingInterceptor = null;
          subject = null;
          managedConnection = null;
          obtainedConnectionTrackingInterceptor = null;
          obtainedConnectionInfo = null;
          releasedConnectionTrackingInterceptor = null;
          releasedConnectionInfo = null;
          gotConnection = false;
          returnedConnection = false;
      }
  
      public void testConnectionRegistration() throws Exception {
          ConnectionInfo connectionInfo = new ConnectionInfo();
          connectionTrackingInterceptor.getConnection(connectionInfo);
          assertTrue("Expected handleObtained call with our connectionTrackingInterceptor",
                  connectionTrackingInterceptor == obtainedConnectionTrackingInterceptor);
          assertTrue("Expected handleObtained call with our connectionInfo",
                  connectionInfo == obtainedConnectionInfo);
          //release connection handle
          connectionTrackingInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected handleReleased call with our connectionTrackingInterceptor",
                      connectionTrackingInterceptor == releasedConnectionTrackingInterceptor);
              assertTrue("Expected handleReleased call with our connectionInfo",
                      connectionInfo == releasedConnectionInfo);
  
      }
  
      //Well, subject is null if this is called directly
      public void testEnterWithNullSubject() throws Exception {
          ConnectionInfo connectionInfo = new ConnectionInfo();
          //easy way to get ManagedConnectionInfo set up
          connectionTrackingInterceptor.getConnection(connectionInfo);
          //reset our test indicator
          gotConnection = false;
          connectionInfos = new HashSet();
          connectionInfos.add(connectionInfo);
          unshareable = new HashSet();
          connectionTrackingInterceptor.enter(connectionInfos, unshareable);
          //expect no re-association
          assertTrue("Expected no connection asked for", !gotConnection);
          assertTrue("Expected no connection returned", !returnedConnection);
      }
  
      public void testEnterWithSameSubject() throws Exception {
          makeSubject("foo");
          testEnterWithNullSubject();
      }
  
      public void testEnterWithChangedSubject() throws Exception {
          testEnterWithSameSubject();
          makeSubject("bar");
          connectionTrackingInterceptor.enter(connectionInfos, unshareable);
          //expect re-association
          assertTrue("Expected connection asked for", gotConnection);
          assertTrue("Expected connection returned", returnedConnection);
      }
  
      public void testExitWithNonDissociatableConnection() throws Exception {
          managedConnection = new TestPlainManagedConnection();
          testEnterWithSameSubject();
          connectionTrackingInterceptor.exit(connectionInfos, unshareable);
          assertTrue("Expected no connection returned", !returnedConnection);
          assertEquals("Expected one info in connectionInfos", connectionInfos.size(), 1);
      }
  
      public void testExitWithDissociatableConnection() throws Exception {
          managedConnection = new TestDissociatableManagedConnection();
          testEnterWithSameSubject();
          connectionTrackingInterceptor.exit(connectionInfos, unshareable);
          assertTrue("Expected connection returned", returnedConnection);
          assertEquals("Expected no infos in connectionInfos", connectionInfos.size(), 0);
      }
  
      private void makeSubject(String principalName) {
          subject = new Subject();
          Set principals = subject.getPrincipals();
          principals.add(new TestPrincipal(principalName));
      }
  
      //ConnectionTracker interface
      public void handleObtained(
              ConnectionTrackingInterceptor connectionTrackingInterceptor,
              ConnectionInfo connectionInfo) {
          obtainedConnectionTrackingInterceptor = connectionTrackingInterceptor;
          obtainedConnectionInfo = connectionInfo;
      }
  
      public void handleReleased(
              ConnectionTrackingInterceptor connectionTrackingInterceptor,
              ConnectionInfo connectionInfo) {
          releasedConnectionTrackingInterceptor = connectionTrackingInterceptor;
          releasedConnectionInfo = connectionInfo;
      }
  
      public ConnectorTransactionContext getConnectorTransactionContext() {
          return null;
      }
  
      //ConnectionInterceptor interface
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          managedConnectionInfo.setConnectionEventListener(new GeronimoConnectionEventListener(null, managedConnectionInfo));
          managedConnectionInfo.setSubject(subject);
          managedConnectionInfo.setManagedConnection(managedConnection);
          connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
          gotConnection = true;
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
          returnedConnection = true;
      }
  
      //SecurityDomain interface
      public Subject getSubject() {
          return subject;
      }
  
      private static class TestPrincipal implements Principal {
  
          private final String name;
  
          public TestPrincipal(String name) {
              this.name = name;
          }
          public String getName() {
              return name;
          }
  
      }
  
      private static class TestPlainManagedConnection implements ManagedConnection {
          public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
              return null;
          }
  
          public void destroy() throws ResourceException {
          }
  
          public void cleanup() throws ResourceException {
          }
  
          public void associateConnection(Object connection) throws ResourceException {
          }
  
          public void addConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public void removeConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public XAResource getXAResource() throws ResourceException {
              return null;
          }
  
          public LocalTransaction getLocalTransaction() throws ResourceException {
              return null;
          }
  
          public ManagedConnectionMetaData getMetaData() throws ResourceException {
              return null;
          }
  
          public void setLogWriter(PrintWriter out) throws ResourceException {
          }
  
          public PrintWriter getLogWriter() throws ResourceException {
              return null;
          }
  
      }
  
      private static class TestDissociatableManagedConnection implements ManagedConnection, DissociatableManagedConnection {
          public void dissociateConnections() throws ResourceException {
          }
  
          public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
              return null;
          }
  
          public void destroy() throws ResourceException {
          }
  
          public void cleanup() throws ResourceException {
          }
  
          public void associateConnection(Object connection) throws ResourceException {
          }
  
          public void addConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public void removeConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public XAResource getXAResource() throws ResourceException {
              return null;
          }
  
          public LocalTransaction getLocalTransaction() throws ResourceException {
              return null;
          }
  
          public ManagedConnectionMetaData getMetaData() throws ResourceException {
              return null;
          }
  
          public void setLogWriter(PrintWriter out) throws ResourceException {
          }
  
          public PrintWriter getLogWriter() throws ResourceException {
              return null;
          }
  
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptorTest.java
  
  Index: LocalXAResourceInsertionInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import java.io.PrintWriter;
  
  import javax.resource.ResourceException;
  import javax.resource.spi.LocalTransaction;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.ConnectionEventListener;
  import javax.resource.spi.ManagedConnectionMetaData;
  import javax.security.auth.Subject;
  import javax.transaction.xa.XAResource;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class LocalXAResourceInsertionInterceptorTest extends TestCase
      implements ConnectionInterceptor {
  
      private LocalXAResourceInsertionInterceptor localXAResourceInsertionInterceptor;
      private LocalTransaction localTransaction;
  
      protected void setUp() throws Exception {
          localXAResourceInsertionInterceptor = new LocalXAResourceInsertionInterceptor(this);
      }
  
      protected void tearDown() throws Exception {
          localXAResourceInsertionInterceptor = null;
      }
  
      public void testInsertLocalXAResource() throws Exception {
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo = new ConnectionInfo(managedConnectionInfo);
          localXAResourceInsertionInterceptor.getConnection(connectionInfo);
          LocalXAResource returnedLocalXAResource = (LocalXAResource)managedConnectionInfo.getXAResource();
          assertTrue("Expected the same LocalTransaction", localTransaction == returnedLocalXAResource.localTransaction);
      }
  
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          localTransaction = new TestLocalTransaction();
          TestManagedConnection managedConnection = new TestManagedConnection(localTransaction);
          ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
          managedConnectionInfo.setManagedConnection(managedConnection);
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
      }
  
      private static class TestLocalTransaction implements LocalTransaction {
          public void begin() throws ResourceException {
          }
  
          public void commit() throws ResourceException {
          }
  
          public void rollback() throws ResourceException {
          }
  
      }
  
      private static class TestManagedConnection implements ManagedConnection {
  
          private final LocalTransaction localTransaction;
  
          public TestManagedConnection(LocalTransaction localTransaction) {
              this.localTransaction = localTransaction;
          }
  
          public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
              return null;
          }
  
          public void destroy() throws ResourceException {
          }
  
          public void cleanup() throws ResourceException {
          }
  
          public void associateConnection(Object connection) throws ResourceException {
          }
  
          public void addConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public void removeConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public XAResource getXAResource() throws ResourceException {
              return null;
          }
  
          public LocalTransaction getLocalTransaction() throws ResourceException {
              return localTransaction;
          }
  
          public ManagedConnectionMetaData getMetaData() throws ResourceException {
              return null;
          }
  
          public void setLogWriter(PrintWriter out) throws ResourceException {
          }
  
          public PrintWriter getLogWriter() throws ResourceException {
              return null;
          }
  
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/SubjectInterceptorTest.java
  
  Index: SubjectInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import javax.security.auth.Subject;
  import javax.resource.ResourceException;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class SubjectInterceptorTest extends TestCase
      implements SecurityDomain, ConnectionInterceptor{
  
      private SubjectInterceptor subjectInterceptor;
  
      private Subject subject;
  
      private ConnectionInfo obtainedConnectionInfo;
      private ConnectionInfo returnedConnectionInfo;
  
      protected void setUp() throws Exception {
          subjectInterceptor = new SubjectInterceptor(this, this);
      }
  
      protected void tearDown() throws Exception {
          subjectInterceptor = null;
          subject = null;
      }
  
      public void testGetConnection() throws Exception {
          subject = new Subject();
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo = new ConnectionInfo(managedConnectionInfo);
          subjectInterceptor.getConnection(connectionInfo);
          assertTrue("Expected call to next with same connectionInfo", connectionInfo == obtainedConnectionInfo);
          assertTrue("Expected the same managedConnectionInfo", managedConnectionInfo == connectionInfo.getManagedConnectionInfo());
          assertTrue("Expected supplied subject to be inserted", subject == managedConnectionInfo.getSubject());
      }
  
      public void testReturnConnection() throws Exception {
          ConnectionInfo connectionInfo = new ConnectionInfo();
          subjectInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected call to next with same connectionInfo", connectionInfo == returnedConnectionInfo);
      }
  
  
      public Subject getSubject() {
          return subject;
      }
  
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          obtainedConnectionInfo = connectionInfo;
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
          returnedConnectionInfo = connectionInfo;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/TransactionCachingInterceptorTest.java
  
  Index: TransactionCachingInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import javax.resource.ResourceException;
  import javax.transaction.TransactionManager;
  import javax.transaction.Transaction;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
  import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class TransactionCachingInterceptorTest extends TestCase
          implements ConnectionInterceptor, ConnectionTracker {
  
      private TransactionManager transactionManager;
      private TransactionCachingInterceptor transactionCachingInterceptor;
      private DefaultTransactionContext defaultTransactionContext;
      private boolean gotConnection;
      private boolean returnedConnection;
  
      protected void setUp() throws Exception {
          transactionManager = new TransactionManagerImpl();
          transactionCachingInterceptor = new TransactionCachingInterceptor(this, this);
          gotConnection = false;
          returnedConnection = false;
      }
  
      protected void tearDown() throws Exception {
          transactionManager = null;
          transactionCachingInterceptor = null;
      }
  
      public void testGetConnectionInTransaction() throws Exception {
          transactionManager.begin();
          Transaction transaction = transactionManager.getTransaction();
          defaultTransactionContext = new DefaultTransactionContext(transaction);
          ConnectionInfo connectionInfo1 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo1);
          assertTrue("Expected to get an initial connection", gotConnection);
          assertTrue("Expected nothing returned yet", !returnedConnection);
          assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                  connectionInfo1.getManagedConnectionInfo() == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
          gotConnection = false;
          ConnectionInfo connectionInfo2 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo2);
          assertTrue("Expected to not get a second connection", !gotConnection);
          assertTrue("Expected nothing returned yet", !returnedConnection);
          assertTrue("Expected the same ManagedConnectionInfo in both ConnectionInfos",
                  connectionInfo1.getManagedConnectionInfo() == connectionInfo2.getManagedConnectionInfo());
          assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                  connectionInfo1.getManagedConnectionInfo() == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
          //commit, see if connection returned.
          //we didn't create any handles, so the "ManagedConnection" should be returned.
          assertTrue("Expected TransactionContext to report active", defaultTransactionContext.isActive());
          transactionManager.commit();
          assertTrue("Expected connection to be returned", returnedConnection);
          assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  
      }
  
      public void testGetConnectionOutsideTransaction() throws Exception {
          defaultTransactionContext = new DefaultTransactionContext(null);
          ConnectionInfo connectionInfo1 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo1);
          assertTrue("Expected to get an initial connection", gotConnection);
          assertTrue("Expected nothing returned yet", !returnedConnection);
          assertTrue("Expected no ManagedConnectionInfo in the TransactionContext",
                  null == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
          gotConnection = false;
          ConnectionInfo connectionInfo2 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo2);
          assertTrue("Expected to get a second connection", gotConnection);
          assertTrue("Expected nothing returned yet", !returnedConnection);
          assertTrue("Expected different ManagedConnectionInfo in both ConnectionInfos",
                  connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
          assertTrue("Expected no ManagedConnectionInfo in the TransactionContext",
                  null == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
          //we didn't create any handles, so the "ManagedConnection" should be returned.
          assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
          transactionCachingInterceptor.returnConnection(connectionInfo1, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected connection to be returned", returnedConnection);
          returnedConnection = false;
          transactionCachingInterceptor.returnConnection(connectionInfo2, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected connection to be returned", returnedConnection);
  
          assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
  
      }
  
      public void testTransactionIndependence() throws Exception {
          transactionManager.begin();
          Transaction transaction1 = transactionManager.getTransaction();
          defaultTransactionContext = new DefaultTransactionContext(transaction1);
          DefaultTransactionContext defaultTransactionContext1 = defaultTransactionContext;
          ConnectionInfo connectionInfo1 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo1);
          gotConnection = false;
  
          //start a second transaction
          transactionManager.suspend();
          transactionManager.begin();
          Transaction transaction2 = transactionManager.getTransaction();
          defaultTransactionContext = new DefaultTransactionContext(transaction2);
          ConnectionInfo connectionInfo2 = new ConnectionInfo();
          transactionCachingInterceptor.getConnection(connectionInfo2);
          assertTrue("Expected to get a second connection", gotConnection);
          assertTrue("Expected nothing returned yet", !returnedConnection);
          assertTrue("Expected different ManagedConnectionInfo in each ConnectionInfos",
                  connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
          assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
                  connectionInfo2.getManagedConnectionInfo() == defaultTransactionContext.getManagedConnectionInfo(transactionCachingInterceptor));
          //commit 2nd transaction, see if connection returned.
          //we didn't create any handles, so the "ManagedConnection" should be returned.
          assertTrue("Expected TransactionContext to report active", defaultTransactionContext.isActive());
          transactionManager.commit();
          assertTrue("Expected connection to be returned", returnedConnection);
          assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
          returnedConnection = false;
          //resume first transaction
          transactionManager.resume(transaction1);
          defaultTransactionContext = defaultTransactionContext1;
          transactionManager.commit();
          assertTrue("Expected connection to be returned", returnedConnection);
          assertTrue("Expected TransactionContext to report inactive", !defaultTransactionContext.isActive());
      }
  
  //interface implementations
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          gotConnection = true;
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          managedConnectionInfo.setConnectionEventListener(new GeronimoConnectionEventListener(null, managedConnectionInfo));
          connectionInfo.setManagedConnectionInfo(managedConnectionInfo);
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
          returnedConnection = true;
      }
  
      public void handleObtained(
              ConnectionTrackingInterceptor connectionTrackingInterceptor,
              ConnectionInfo connectionInfo) {
      }
  
      public void handleReleased(
              ConnectionTrackingInterceptor connectionTrackingInterceptor,
              ConnectionInfo connectionInfo) {
      }
  
      public ConnectorTransactionContext getConnectorTransactionContext() {
          return defaultTransactionContext;
      }
  
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java
  
  Index: TransactionEnlistingInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import javax.resource.ResourceException;
  import javax.transaction.TransactionManager;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  import javax.transaction.xa.XAException;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class TransactionEnlistingInterceptorTest extends TestCase
      implements ConnectionInterceptor, XAResource {
  
      private TransactionEnlistingInterceptor transactionEnlistingInterceptor;
      private TransactionManager transactionManager;
      private boolean started;
      private boolean ended;
      private boolean returned;
      private boolean committed;
  
      protected void setUp() throws Exception {
          transactionManager = new TransactionManagerImpl();
          transactionEnlistingInterceptor = new TransactionEnlistingInterceptor(this, transactionManager);
      }
  
      protected void tearDown() throws Exception {
          transactionManager = null;
          transactionEnlistingInterceptor = null;
          started = false;
          ended = false;
          returned = false;
          committed = false;
      }
  
      public void testNoTransaction() throws Exception {
          ConnectionInfo connectionInfo = getConnectionInfo();
          transactionEnlistingInterceptor.getConnection(connectionInfo);
          assertTrue("Expected not started", !started);
          assertTrue("Expected not ended", !ended);
          transactionEnlistingInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected returned", returned);
          assertTrue("Expected not committed", !committed);
      }
  
      public void testTransaction() throws Exception {
          ConnectionInfo connectionInfo = getConnectionInfo();
          transactionManager.begin();
          transactionEnlistingInterceptor.getConnection(connectionInfo);
          assertTrue("Expected started", started);
          assertTrue("Expected not ended", !ended);
          started = false;
          transactionEnlistingInterceptor.returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE);
          assertTrue("Expected not started", !started);
          assertTrue("Expected ended", ended);
          assertTrue("Expected returned", returned);
          transactionManager.commit();
          assertTrue("Expected committed", committed);
      }
  
      private ConnectionInfo getConnectionInfo() {
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          return new ConnectionInfo(managedConnectionInfo);
      }
  
      //ConnectionInterceptor
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
          managedConnectionInfo.setXAResource(this);
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
          returned = true;
      }
  
      //XAResource
      public void commit(Xid xid, boolean onePhase) throws XAException {
          committed = true;
      }
  
      public void end(Xid xid, int flags) throws XAException {
          ended = true;
      }
  
      public void forget(Xid xid) throws XAException {
      }
  
      public int getTransactionTimeout() throws XAException {
          return 0;
      }
  
      public boolean isSameRM(XAResource xaResource) throws XAException {
          return false;
      }
  
      public int prepare(Xid xid) throws XAException {
          return 0;
      }
  
      public Xid[] recover(int flag) throws XAException {
          return new Xid[0];
      }
  
      public void rollback(Xid xid) throws XAException {
      }
  
      public boolean setTransactionTimeout(int seconds) throws XAException {
          return false;
      }
  
      public void start(Xid xid, int flags) throws XAException {
          started = true;
      }
  
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptorTest.java
  
  Index: XAResourceInsertionInterceptorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound;
  
  import java.io.PrintWriter;
  
  import javax.resource.ResourceException;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.ConnectionEventListener;
  import javax.resource.spi.LocalTransaction;
  import javax.resource.spi.ManagedConnectionMetaData;
  import javax.transaction.xa.XAResource;
  import javax.transaction.xa.Xid;
  import javax.transaction.xa.XAException;
  import javax.security.auth.Subject;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class XAResourceInsertionInterceptorTest extends TestCase
      implements ConnectionInterceptor {
  
      private XAResourceInsertionInterceptor xaResourceInsertionInterceptor;
      private XAResource xaResource;
  
      protected void setUp() throws Exception {
          xaResourceInsertionInterceptor = new XAResourceInsertionInterceptor(this);
      }
  
      protected void tearDown() throws Exception {
          xaResourceInsertionInterceptor = null;
      }
  
      public void testInsertXAResource() throws Exception {
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo = new ConnectionInfo(managedConnectionInfo);
          xaResourceInsertionInterceptor.getConnection(connectionInfo);
          assertTrue("Expected the same XAResource", xaResource == managedConnectionInfo.getXAResource());
      }
  
      public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
          xaResource = new TestXAResource();
          ManagedConnection managedConnection = new TestManagedConnection(xaResource);
          ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
          managedConnectionInfo.setManagedConnection(managedConnection);
      }
  
      public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
      }
  
      private static class TestXAResource implements XAResource {
          public void commit(Xid xid, boolean onePhase) throws XAException {
          }
  
          public void end(Xid xid, int flags) throws XAException {
          }
  
          public void forget(Xid xid) throws XAException {
          }
  
          public int getTransactionTimeout() throws XAException {
              return 0;
          }
  
          public boolean isSameRM(XAResource xaResource) throws XAException {
              return false;
          }
  
          public int prepare(Xid xid) throws XAException {
              return 0;
          }
  
          public Xid[] recover(int flag) throws XAException {
              return new Xid[0];
          }
  
          public void rollback(Xid xid) throws XAException {
          }
  
          public boolean setTransactionTimeout(int seconds) throws XAException {
              return false;
          }
  
          public void start(Xid xid, int flags) throws XAException {
          }
  
      }
  
      private static class TestManagedConnection implements ManagedConnection {
  
          private final XAResource xaResource;
  
          public TestManagedConnection(XAResource xaResource) {
              this.xaResource = xaResource;
          }
          public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
              return null;
          }
  
          public void destroy() throws ResourceException {
          }
  
          public void cleanup() throws ResourceException {
          }
  
          public void associateConnection(Object connection) throws ResourceException {
          }
  
          public void addConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public void removeConnectionEventListener(ConnectionEventListener listener) {
          }
  
          public XAResource getXAResource() throws ResourceException {
              return xaResource;
          }
  
          public LocalTransaction getLocalTransaction() throws ResourceException {
              return null;
          }
  
          public ManagedConnectionMetaData getMetaData() throws ResourceException {
              return null;
          }
  
          public void setLogWriter(PrintWriter out) throws ResourceException {
          }
  
          public PrintWriter getLogWriter() throws ResourceException {
              return null;
          }
  
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/connector/outbound/connectiontracking/ConnectionTrackingCoordinatorTest.java
  
  Index: ConnectionTrackingCoordinatorTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.outbound.connectiontracking;
  
  import java.util.Set;
  import java.util.HashSet;
  import java.util.Map;
  
  import javax.security.auth.Subject;
  import javax.transaction.TransactionManager;
  import javax.transaction.Transaction;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.connector.outbound.ConnectionTrackingInterceptor;
  import org.apache.geronimo.connector.outbound.SecurityDomain;
  import org.apache.geronimo.connector.outbound.ConnectorComponentContext;
  import org.apache.geronimo.connector.outbound.ConnectionInfo;
  import org.apache.geronimo.connector.outbound.ManagedConnectionInfo;
  import org.apache.geronimo.connector.outbound.ConnectorTransactionContext;
  import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
  import org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
  import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/12/09 04:17:39 $
   *
   * */
  public class ConnectionTrackingCoordinatorTest extends TestCase
          implements SecurityDomain {
  
      private static final String name1 = "foo";
      private static final String name2 = "bar";
      private ConnectionTrackingCoordinator connectionTrackingCoordinator;
      private ConnectionTrackingInterceptor key1;
      private ConnectionTrackingInterceptor key2;
      private Subject subject = null;
      private Set unshareableResources;
      private TransactionManager transactionManager;
  
  
      protected void setUp() throws Exception {
          connectionTrackingCoordinator = new ConnectionTrackingCoordinator();
          key1 = new ConnectionTrackingInterceptor(null, name1, connectionTrackingCoordinator, this);
          key2 = new ConnectionTrackingInterceptor(null, name2, connectionTrackingCoordinator, this);
          unshareableResources = new HashSet();
          transactionManager = new TransactionManagerImpl();
      }
  
      protected void tearDown() throws Exception {
          connectionTrackingCoordinator = null;
          key1 = null;
          key2 = null;
          transactionManager = null;
      }
  
      public void testSimpleComponentContextLifecyle() throws Exception {
          DefaultComponentContext componentContext = new DefaultComponentContext();
          ConnectorComponentContext oldComponentContext = connectionTrackingCoordinator.enter(componentContext, unshareableResources);
          assertNull("Expected old component context to be null", oldComponentContext);
          //give the context a ConnectionInfo
          ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo = new ConnectionInfo(managedConnectionInfo);
          connectionTrackingCoordinator.handleObtained(key1, connectionInfo);
          connectionTrackingCoordinator.exit(oldComponentContext, unshareableResources);
          Map connectionManagerMap = componentContext.getConnectionManagerMap();
          Set infos = (Set) connectionManagerMap.get(key1);
          assertEquals("Expected one connection for key1", 1, infos.size());
          assertTrue("Expected to get supplied ConnectionInfo from infos", connectionInfo == infos.iterator().next());
  
          //Enter again, and close the handle
          oldComponentContext = connectionTrackingCoordinator.enter(componentContext, unshareableResources);
          assertNull("Expected old component context to be null", oldComponentContext);
          connectionTrackingCoordinator.handleReleased(key1, connectionInfo);
          connectionTrackingCoordinator.exit(oldComponentContext, unshareableResources);
          connectionManagerMap = componentContext.getConnectionManagerMap();
          infos = (Set) connectionManagerMap.get(key1);
          assertEquals("Expected no connection set for key1", null, infos);
      }
  
      public void testNestedComponentContextLifecyle() throws Exception {
          DefaultComponentContext componentContext1 = new DefaultComponentContext();
          ConnectorComponentContext oldComponentContext1 = connectionTrackingCoordinator.enter(componentContext1, unshareableResources);
          assertNull("Expected old component context to be null", oldComponentContext1);
          //give the context a ConnectionInfo
          ManagedConnectionInfo managedConnectionInfo1 = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo1 = new ConnectionInfo(managedConnectionInfo1);
          connectionTrackingCoordinator.handleObtained(key1, connectionInfo1);
  
          //Simulate calling another component
          DefaultComponentContext componentContext2 = new DefaultComponentContext();
          ConnectorComponentContext oldComponentContext2 = connectionTrackingCoordinator.enter(componentContext2, unshareableResources);
          assertTrue("Expected returned component context to be componentContext1", oldComponentContext2 == componentContext1);
          //give the context a ConnectionInfo
          ManagedConnectionInfo managedConnectionInfo2 = new ManagedConnectionInfo(null, null);
          ConnectionInfo connectionInfo2 = new ConnectionInfo(managedConnectionInfo2);
          connectionTrackingCoordinator.handleObtained(key2, connectionInfo2);
  
          connectionTrackingCoordinator.exit(oldComponentContext2, unshareableResources);
          Map connectionManagerMap2 = componentContext2.getConnectionManagerMap();
          Set infos2 = (Set) connectionManagerMap2.get(key2);
          assertEquals("Expected one connection for key2", 1, infos2.size());
          assertTrue("Expected to get supplied ConnectionInfo from infos", connectionInfo2 == infos2.iterator().next());
          assertEquals("Expected no connection for key1", null, connectionManagerMap2.get(key1));
  
  
          connectionTrackingCoordinator.exit(oldComponentContext1, unshareableResources);
          Map connectionManagerMap1 = componentContext1.getConnectionManagerMap();
          Set infos1 = (Set) connectionManagerMap1.get(key1);
          assertEquals("Expected one connection for key1", 1, infos1.size());
          assertTrue("Expected to get supplied ConnectionInfo from infos", connectionInfo1 == infos1.iterator().next());
          assertEquals("Expected no connection for key2", null, connectionManagerMap1.get(key2));
  
          //Enter again, and close the handle
          oldComponentContext1 = connectionTrackingCoordinator.enter(componentContext1, unshareableResources);
          assertNull("Expected old component context to be null", oldComponentContext1);
          connectionTrackingCoordinator.handleReleased(key1, connectionInfo1);
          connectionTrackingCoordinator.exit(oldComponentContext1, unshareableResources);
          connectionManagerMap1 = componentContext1.getConnectionManagerMap();
          infos1 = (Set) connectionManagerMap1.get(key1);
          assertEquals("Expected no connection set for key1", null, infos1);
      }
  
      public void testSimpleTransactionContextLifecycle() throws Exception {
          transactionManager.begin();
          Transaction transaction = transactionManager.getTransaction();
          DefaultTransactionContext transactionContext = new DefaultTransactionContext(transaction);
          ConnectorTransactionContext oldTransactionContext = connectionTrackingCoordinator.setConnectorTransactionContext(transactionContext);
          assertNull("Expected no old transactionContext", oldTransactionContext);
          ConnectorTransactionContext availableTransactionContext = connectionTrackingCoordinator.getConnectorTransactionContext();
          assertTrue("Expected the same transactionContext as we sent in", transactionContext == availableTransactionContext);
  
          ConnectorTransactionContext exitingTransactionContext = connectionTrackingCoordinator.setConnectorTransactionContext(null);
          assertTrue("Expected the same transactionContext as we sent in", transactionContext == exitingTransactionContext);
          ConnectorTransactionContext availableTransactionContext2 = connectionTrackingCoordinator.getConnectorTransactionContext();
          assertNull("Expected no transactionContext", availableTransactionContext2);
      }
  
      public Subject getSubject() {
          return subject;
      }
  }
  
  
  

Mime
View raw message