Search in sources :

Example 16 with CciTemplate

use of org.springframework.jca.cci.core.CciTemplate in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteInputOutput.

@Test
public void testTemplateExecuteInputOutput() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    Record inputRecord = mock(Record.class);
    Record outputRecord = mock(Record.class);
    InteractionSpec interactionSpec = mock(InteractionSpec.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.execute(interactionSpec, inputRecord, outputRecord);
    verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
    verify(interaction).close();
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) Interaction(javax.resource.cci.Interaction) InteractionSpec(javax.resource.cci.InteractionSpec) Connection(javax.resource.cci.Connection) MappedRecord(javax.resource.cci.MappedRecord) IndexedRecord(javax.resource.cci.IndexedRecord) Record(javax.resource.cci.Record) CciTemplate(org.springframework.jca.cci.core.CciTemplate) Test(org.junit.Test)

Example 17 with CciTemplate

use of org.springframework.jca.cci.core.CciTemplate in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteInputTrueWithCreator2.

@Test
public void testTemplateExecuteInputTrueWithCreator2() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    RecordFactory recordFactory = mock(RecordFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    RecordCreator creator = mock(RecordCreator.class);
    Record inputRecord = mock(Record.class);
    final Record outputRecord = mock(Record.class);
    InteractionSpec interactionSpec = mock(InteractionSpec.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
    given(connection.createInteraction()).willReturn(interaction);
    given(creator.createRecord(recordFactory)).willReturn(outputRecord);
    given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.setOutputRecordCreator(creator);
    ct.execute(interactionSpec, inputRecord);
    verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
    verify(interaction).close();
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) RecordFactory(javax.resource.cci.RecordFactory) NotSupportedRecordFactory(org.springframework.jca.cci.connection.NotSupportedRecordFactory) Interaction(javax.resource.cci.Interaction) RecordCreator(org.springframework.jca.cci.core.RecordCreator) InteractionSpec(javax.resource.cci.InteractionSpec) Connection(javax.resource.cci.Connection) MappedRecord(javax.resource.cci.MappedRecord) IndexedRecord(javax.resource.cci.IndexedRecord) Record(javax.resource.cci.Record) CciTemplate(org.springframework.jca.cci.core.CciTemplate) Test(org.junit.Test)

Example 18 with CciTemplate

use of org.springframework.jca.cci.core.CciTemplate in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteInputTrueTrue.

@Test
public void testTemplateExecuteInputTrueTrue() throws ResourceException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    Record inputOutputRecord = mock(Record.class);
    InteractionSpec interactionSpec = mock(InteractionSpec.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord)).willReturn(true);
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
    verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord);
    verify(interaction).close();
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) Interaction(javax.resource.cci.Interaction) InteractionSpec(javax.resource.cci.InteractionSpec) Connection(javax.resource.cci.Connection) MappedRecord(javax.resource.cci.MappedRecord) IndexedRecord(javax.resource.cci.IndexedRecord) Record(javax.resource.cci.Record) CciTemplate(org.springframework.jca.cci.core.CciTemplate) Test(org.junit.Test)

Example 19 with CciTemplate

use of org.springframework.jca.cci.core.CciTemplate in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteInputExtractorFalse.

@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputExtractorFalse() throws ResourceException, SQLException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    Interaction interaction = mock(Interaction.class);
    RecordExtractor<Object> extractor = mock(RecordExtractor.class);
    Record inputRecord = mock(Record.class);
    Record outputRecord = mock(Record.class);
    InteractionSpec interactionSpec = mock(InteractionSpec.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.createInteraction()).willReturn(interaction);
    given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
    given(extractor.extractData(outputRecord)).willReturn(new Object());
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.execute(interactionSpec, inputRecord, extractor);
    verify(extractor).extractData(outputRecord);
    verify(interaction).close();
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) Interaction(javax.resource.cci.Interaction) InteractionSpec(javax.resource.cci.InteractionSpec) Connection(javax.resource.cci.Connection) MappedRecord(javax.resource.cci.MappedRecord) IndexedRecord(javax.resource.cci.IndexedRecord) Record(javax.resource.cci.Record) CciTemplate(org.springframework.jca.cci.core.CciTemplate) Test(org.junit.Test)

Example 20 with CciTemplate

use of org.springframework.jca.cci.core.CciTemplate in project spring-framework by spring-projects.

the class CciTemplateTests method testTemplateExecuteConnectionCallback.

@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteConnectionCallback() throws ResourceException, SQLException {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    Connection connection = mock(Connection.class);
    ConnectionCallback<Object> connectionCallback = mock(ConnectionCallback.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connectionCallback.doInConnection(connection, connectionFactory)).willReturn(new Object());
    CciTemplate ct = new CciTemplate(connectionFactory);
    ct.execute(connectionCallback);
    verify(connectionCallback).doInConnection(connection, connectionFactory);
    verify(connection).close();
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) Connection(javax.resource.cci.Connection) CciTemplate(org.springframework.jca.cci.core.CciTemplate) Test(org.junit.Test)

Aggregations

ConnectionFactory (javax.resource.cci.ConnectionFactory)21 Test (org.junit.Test)21 CciTemplate (org.springframework.jca.cci.core.CciTemplate)21 Connection (javax.resource.cci.Connection)19 Interaction (javax.resource.cci.Interaction)18 InteractionSpec (javax.resource.cci.InteractionSpec)17 Record (javax.resource.cci.Record)17 IndexedRecord (javax.resource.cci.IndexedRecord)16 MappedRecord (javax.resource.cci.MappedRecord)16 RecordFactory (javax.resource.cci.RecordFactory)10 NotSupportedRecordFactory (org.springframework.jca.cci.connection.NotSupportedRecordFactory)10 RecordCreator (org.springframework.jca.cci.core.RecordCreator)9 LocalTransaction (javax.resource.cci.LocalTransaction)2 CciLocalTransactionManager (org.springframework.jca.cci.connection.CciLocalTransactionManager)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 NotSupportedException (javax.resource.NotSupportedException)1 ResourceException (javax.resource.ResourceException)1 ConnectionSpec (javax.resource.cci.ConnectionSpec)1 ResultSet (javax.resource.cci.ResultSet)1