use of javax.resource.cci.Connection in project spring-framework by spring-projects.
the class CciTemplateTests method testTemplateExecuteInputFalseTrue.
@Test
public void testTemplateExecuteInputFalseTrue() 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)).willReturn(null);
CciTemplate ct = new CciTemplate(connectionFactory);
Record tmpOutputRecord = ct.execute(interactionSpec, inputOutputRecord);
assertNull(tmpOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
use of javax.resource.cci.Connection in project spring-framework by spring-projects.
the class CciTemplateTests method testTemplateExecuteInputGeneratorExtractorTrueWithCreator.
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputGeneratorExtractorTrueWithCreator() throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
RecordFactory recordFactory = mock(RecordFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
RecordCreator generator = mock(RecordCreator.class);
RecordExtractor<Object> extractor = mock(RecordExtractor.class);
RecordCreator creator = mock(RecordCreator.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
Object obj = new Object();
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(creator.createRecord(recordFactory)).willReturn(outputRecord);
given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
given(generator.createRecord(recordFactory)).willReturn(inputRecord);
given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
given(extractor.extractData(outputRecord)).willReturn(obj);
CciTemplate ct = new CciTemplate(connectionFactory);
ct.setOutputRecordCreator(creator);
assertEquals(obj, ct.execute(interactionSpec, generator, extractor));
verify(interaction).close();
verify(connection).close();
}
use of javax.resource.cci.Connection in project spring-framework by spring-projects.
the class CciTemplateTests method testTemplateExecuteInputTrueTrueWithCreator.
@Test
public void testTemplateExecuteInputTrueTrueWithCreator() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
RecordCreator creator = mock(RecordCreator.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.setOutputRecordCreator(creator);
ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
use of javax.resource.cci.Connection in project spring-framework by spring-projects.
the class CciTemplateTests method testTemplateExecuteInputGeneratorExtractorFalse.
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputGeneratorExtractorFalse() throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
RecordFactory recordFactory = mock(RecordFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
RecordCreator generator = mock(RecordCreator.class);
RecordExtractor<Object> extractor = mock(RecordExtractor.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(generator.createRecord(recordFactory)).willReturn(inputRecord);
given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
given(extractor.extractData(outputRecord)).willReturn(new Object());
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionSpec, generator, extractor);
verify(extractor).extractData(outputRecord);
verify(interaction).close();
verify(connection).close();
}
use of javax.resource.cci.Connection in project spring-framework by spring-projects.
the class CciTemplateTests method testTemplateExecuteInteractionCallback.
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInteractionCallback() throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
InteractionCallback<Object> interactionCallback = mock(InteractionCallback.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interactionCallback.doInInteraction(interaction, connectionFactory)).willReturn(new Object());
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionCallback);
verify(interactionCallback).doInInteraction(interaction, connectionFactory);
verify(interaction).close();
verify(connection).close();
}
Aggregations