Search in sources :

Example 11 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project cxf by apache.

the class DummyManagedConnectionFactoryImpl method testMatchConnectionInvalidatedWithSameConnectioRequestInfo.

@Test
public void testMatchConnectionInvalidatedWithSameConnectioRequestInfo() throws Exception {
    Subject subject = null;
    Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>();
    ConnectionRequestInfo cri = new DummyConnectionRequestInfo();
    DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri, subject);
    con1.setBound(true);
    con1.setCon(connectionSet);
    connectionSet.add(con1);
    ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri);
    assertTrue("Connection must be null", mcon == null);
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) Subject(javax.security.auth.Subject) ConnectionRequestInfo(javax.resource.spi.ConnectionRequestInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project cxf by apache.

the class DummyManagedConnectionFactoryImpl method testMatchConnectionDifferentConnectioRequestInfoNotBound.

@Test
public void testMatchConnectionDifferentConnectioRequestInfoNotBound() throws Exception {
    ConnectionRequestInfo cri1 = new DummyConnectionRequestInfo();
    ConnectionRequestInfo cri2 = new DummyConnectionRequestInfo();
    Subject subject = null;
    assertTrue("request info object are differnt", cri1 != cri2);
    Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>();
    DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri1, subject);
    connectionSet.add(con1);
    ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri2);
    assertEquals("incorrect connection returned", con1, mcon);
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) ConnectionRequestInfo(javax.resource.spi.ConnectionRequestInfo) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project cxf by apache.

the class DummyManagedConnectionFactoryImpl method testMatchConnectionDifferentConnectioRequestInfoBound.

@Test
public void testMatchConnectionDifferentConnectioRequestInfoBound() throws Exception {
    ConnectionRequestInfo cri1 = new DummyConnectionRequestInfo();
    ConnectionRequestInfo cri2 = new DummyConnectionRequestInfo();
    Subject subject = null;
    assertTrue("request info object are differnt", cri1 != cri2);
    Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>();
    DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri1, subject);
    con1.setBound(true);
    connectionSet.add(con1);
    ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri2);
    assertTrue("should not get a match", mcon == null);
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) ConnectionRequestInfo(javax.resource.spi.ConnectionRequestInfo) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project cxf by apache.

the class DummyManagedConnectionFactoryImpl method testMatchConnectionSameConnectioRequestInfoBound.

@Test
public void testMatchConnectionSameConnectioRequestInfoBound() throws Exception {
    Subject subject = null;
    Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>();
    ConnectionRequestInfo cri = new DummyConnectionRequestInfo();
    DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri, subject);
    con1.setBound(true);
    connectionSet.add(con1);
    ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri);
    assertEquals(con1, mcon);
}
Also used : ManagedConnection(javax.resource.spi.ManagedConnection) Subject(javax.security.auth.Subject) ConnectionRequestInfo(javax.resource.spi.ConnectionRequestInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with ManagedConnection

use of javax.resource.spi.ManagedConnection in project cxf by apache.

the class ManagedConnectionFactoryImplTester method testMatchManagedConnectionsWithBoundConnections.

@Test
public void testMatchManagedConnectionsWithBoundConnections() throws Exception {
    Subject subj = new Subject();
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    ManagedConnectionFactoryImpl factory = EasyMock.createMock(ManagedConnectionFactoryImpl.class);
    factory.getBus();
    // In ManagedConnectionImpl:
    // one for getCXFServiceFromBus , another for createInvocationHandler
    EasyMock.expectLastCall().andReturn(bus).times(4);
    EasyMock.replay(factory);
    ManagedConnectionImpl mc1 = new ManagedConnectionImpl(factory, cri, subj);
    Object connection = mc1.getConnection(subj, cri);
    assertNotNull("connection must not be null.", connection);
    /*
        ManagedConnectionImpl mc2 = new ManagedConnectionImpl(factory, cri2, subj);
        connection = mc2.getConnection(subj, cri2);
        assertNotNull("connection must not be null.", connection);
        */
    // EasyMock.verify(factory);
    Set<ManagedConnection> mcSet = new HashSet<>();
    mcSet.add(mc1);
    // mcSet.add(mc2);
    assertSame("MC1 must be selected.", mci.matchManagedConnections(mcSet, subj, cri), mc1);
    // assertSame("MC2 must be selected.", mci.matchManagedConnections(mcSet, subj, cri2), mc2);
    // assertNull("No connection must be selected.", mci.matchManagedConnections(mcSet, subj, cri3));
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) BusFactory(org.apache.cxf.BusFactory) ManagedConnection(javax.resource.spi.ManagedConnection) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ManagedConnection (javax.resource.spi.ManagedConnection)70 Test (org.junit.Test)24 ResourceException (javax.resource.ResourceException)20 XAResource (javax.transaction.xa.XAResource)17 Iterator (java.util.Iterator)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 SystemException (javax.transaction.SystemException)12 Subject (javax.security.auth.Subject)10 Xid (javax.transaction.xa.Xid)9 HashSet (java.util.HashSet)8 Transaction (javax.transaction.Transaction)7 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)6 ResourceAllocationException (javax.resource.spi.ResourceAllocationException)6 RollbackException (javax.transaction.RollbackException)6 XAException (javax.transaction.xa.XAException)6 Connection (java.sql.Connection)5 NamingException (javax.naming.NamingException)5 ConnectionRequestInfo (javax.resource.spi.ConnectionRequestInfo)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4