Package javax.resource.cci

Examples of javax.resource.cci.ConnectionFactory


    verify(connection).close();
  }

  @Test
  public void testMappingRecordOperation() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    RecordFactory recordFactory = mock(RecordFactory.class);

    Record inputRecord = mock(Record.class);
    Record outputRecord = mock(Record.class);

    InteractionSpec interactionSpec = mock(InteractionSpec.class);

    QueryCallDetector callDetector = mock(QueryCallDetector.class);

    MappingRecordOperationImpl query = new MappingRecordOperationImpl(connectionFactory, interactionSpec);
    query.setCallDetector(callDetector);

    Object inObj = new Object();
    Object outObj = new Object();

    given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
    given(callDetector.callCreateInputRecord(recordFactory, inObj)).willReturn(inputRecord);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
    given(callDetector.callExtractOutputData(outputRecord)).willReturn(outObj);

    assertSame(outObj, query.execute(inObj));
View Full Code Here


    verify(connection).close();
  }

  @Test
  public void testMappingRecordOperationWithOutputRecordCreator() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    RecordFactory recordFactory = mock(RecordFactory.class);

    Record inputRecord = mock(Record.class);
    Record outputRecord = mock(Record.class);

    RecordCreator outputCreator = mock(RecordCreator.class);

    InteractionSpec interactionSpec = mock(InteractionSpec.class);

    QueryCallDetector callDetector = mock(QueryCallDetector.class);

    MappingRecordOperationImpl query = new MappingRecordOperationImpl(connectionFactory, interactionSpec);
    query.setOutputRecordCreator(outputCreator);
    query.setCallDetector(callDetector);

    Object inObj = new Object();
    Object outObj = new Object();

    given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
    given(callDetector.callCreateInputRecord(recordFactory, inObj)).willReturn(inputRecord);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.createInteraction()).willReturn(interaction);
    given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
    given(outputCreator.createRecord(recordFactory)).willReturn(outputRecord);
    given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
    given(callDetector.callExtractOutputData(outputRecord)).willReturn(outObj);

    assertSame(outObj, query.execute(inObj));
View Full Code Here

   * LocalTransaction when CciLocalTransactionManager is specified as
   * transaction manager.
   */
  @Test
  public void testLocalTransactionCommit() throws ResourceException {
    final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    LocalTransaction localTransaction = mock(LocalTransaction.class);
    final Record record = mock(Record.class);
    final InteractionSpec interactionSpec = mock(InteractionSpec.class);

    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.getLocalTransaction()).willReturn(localTransaction);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, record, record)).willReturn(true);
    given(connection.getLocalTransaction()).willReturn(localTransaction);

View Full Code Here

   * LocalTransaction when CciLocalTransactionManager is specified as
   * transaction manager and a non-checked exception is thrown.
   */
  @Test
  public void testLocalTransactionRollback() throws ResourceException {
    final ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    LocalTransaction localTransaction = mock(LocalTransaction.class);
    final Record record = mock(Record.class);
    final InteractionSpec interactionSpec = mock(InteractionSpec.class);

    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.getLocalTransaction()).willReturn(localTransaction);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, record, record)).willReturn(true);
    given(connection.getLocalTransaction()).willReturn(localTransaction);

View Full Code Here

        assertTrue(proxy instanceof ConnectionFactoryExtension);
        assertEquals("SomethingElse", ((ConnectionFactoryExtension)proxy).doSomethingElse());
    }

    public void testSerialization() throws Exception {
        ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(managedConnectionFactoryName, "$getResource");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(proxy);
        oos.flush();
        byte[] bytes = baos.toByteArray();
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        Object proxy2 = ois.readObject();
        assertNotNull(proxy2);
        assertTrue(proxy instanceof ConnectionFactory);
        Connection connection = proxy.getConnection();
        assertNotNull(connection);
        kernel.stopGBean(managedConnectionFactoryName);
        ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
        ConnectionFactory proxy3 = (ConnectionFactory) ois2.readObject();
        try {
            proxy3.getConnection();
            fail();
        } catch (IllegalStateException ise) {
        }
        kernel.startGBean(managedConnectionFactoryName);
        proxy3.getConnection();

    }
View Full Code Here

    public ArrayList<Connection> createConnections(int numConnections,
                                                   String jndiName) throws NamingException, ResourceException {
        ArrayList<Connection> connections = new ArrayList<Connection>();
       
        InitialContext ctx = new InitialContext();
        ConnectionFactory cf = (ConnectionFactory)ctx.lookup("java:" + jndiName);
       
        for(int i = 0; i < numConnections; i++) {
            Connection con = cf.getConnection();
       
            // Actually exercise the connection
            con.getMetaData();
           
            assertNotNull("Null connection", con);
View Full Code Here

        assertTrue(proxy instanceof ConnectionFactoryExtension);
        assertEquals("SomethingElse", ((ConnectionFactoryExtension)proxy).doSomethingElse());
    }

    public void XtestSerialization() throws Exception {
        ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(managedConnectionFactoryName, "$getResource");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(proxy);
        oos.flush();
        byte[] bytes = baos.toByteArray();
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        Object proxy2 = ois.readObject();
        assertNotNull(proxy2);
        assertTrue(proxy instanceof ConnectionFactory);
        Connection connection = proxy.getConnection();
        assertNotNull(connection);
        kernel.stopGBean(managedConnectionFactoryName);
        ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
        ConnectionFactory proxy3 = (ConnectionFactory) ois2.readObject();
        try {
            proxy3.getConnection();
            fail();
        } catch (IllegalStateException ise) {
        }
        kernel.startGBean(managedConnectionFactoryName);
        proxy3.getConnection();

    }
View Full Code Here

        assertTrue(proxy instanceof ConnectionFactoryExtension);
        assertEquals("SomethingElse", ((ConnectionFactoryExtension)proxy).doSomethingElse());
    }

    public void testSerialization() throws Exception {
        ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(managedConnectionFactoryName, "$getResource");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(proxy);
        oos.flush();
        byte[] bytes = baos.toByteArray();
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        Object proxy2 = ois.readObject();
        assertNotNull(proxy2);
        assertTrue(proxy instanceof ConnectionFactory);
        Connection connection = proxy.getConnection();
        assertNotNull(connection);
        kernel.stopGBean(managedConnectionFactoryName);
        ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
        ConnectionFactory proxy3 = (ConnectionFactory) ois2.readObject();
        try {
            proxy3.getConnection();
            fail();
        } catch (IllegalStateException ise) {
        }
        kernel.startGBean(managedConnectionFactoryName);
        proxy3.getConnection();

    }
View Full Code Here

        env.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
        env.put("java.naming.factory.url.pkgs", "org.apache.geronimo.naming");
        env.put("java.naming.provider.url", "rmi://localhost:1099");

        Context ctx = new InitialContext(env);
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("geronimo:" + GLOBAL_NAME);
        assertNotNull(cf);
        kernel.stopGBean(managedConnectionFactoryName);
        try {
            ctx.lookup("geronimo:" + GLOBAL_NAME);
            fail();
        } catch (NamingException ne) {
        }
        kernel.startGBean(managedConnectionFactoryName);
        ConnectionFactory cf2 = (ConnectionFactory) ctx.lookup("geronimo:" + GLOBAL_NAME);
        assertNotNull(cf2);
    }
View Full Code Here

TOP

Related Classes of javax.resource.cci.ConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.