org.springframework.jca.cci.core.CciTemplate Java Examples

The following examples show how to use org.springframework.jca.cci.core.CciTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #4
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #5
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testTemplateExecuteInputFalse() 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)).willReturn(outputRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, inputRecord);

	verify(interaction).execute(interactionSpec, inputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #7
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	ConnectionSpec connectionSpec = mock(ConnectionSpec.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(connectionSpec)).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);

	ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter();
	adapter.setTargetConnectionFactory(connectionFactory);
	adapter.setConnectionSpec(connectionSpec);
	CciTemplate ct = new CciTemplate(adapter);
	ct.execute(interactionSpec, inputRecord, outputRecord);

	verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #8
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #9
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #10
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #11
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #12
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #13
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	ConnectionSpec connectionSpec = mock(ConnectionSpec.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(connectionSpec)).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);

	ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter();
	adapter.setTargetConnectionFactory(connectionFactory);
	adapter.setConnectionSpec(connectionSpec);
	CciTemplate ct = new CciTemplate(adapter);
	ct.execute(interactionSpec, inputRecord, outputRecord);

	verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #14
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #15
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #16
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #17
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	ConnectionSpec connectionSpec = mock(ConnectionSpec.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(connectionSpec)).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);

	ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter();
	adapter.setTargetConnectionFactory(connectionFactory);
	adapter.setConnectionSpec(connectionSpec);
	CciTemplate ct = new CciTemplate(adapter);
	ct.execute(interactionSpec, inputRecord, outputRecord);

	verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #18
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #19
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #20
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #21
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #22
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #23
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #24
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #25
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemplateExecuteInputFalse() 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)).willReturn(outputRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, inputRecord);

	verify(interaction).execute(interactionSpec, inputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #26
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #27
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testTemplateExecuteInputFalse() 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)).willReturn(outputRecord);

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, inputRecord);

	verify(interaction).execute(interactionSpec, inputRecord);
	verify(interaction).close();
	verify(connection).close();
}
 
Example #28
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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();
}
 
Example #29
Source File: CciLocalTransactionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Test if a transaction ( begin / rollback ) is executed on the
 * 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);

	CciLocalTransactionManager tm = new CciLocalTransactionManager();
	tm.setConnectionFactory(connectionFactory);
	TransactionTemplate tt = new TransactionTemplate(tm);

	try {
		tt.execute(new TransactionCallback<Void>() {
			@Override
			public Void doInTransaction(TransactionStatus status) {
				assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(connectionFactory));
				CciTemplate ct = new CciTemplate(connectionFactory);
				ct.execute(interactionSpec, record, record);
				throw new DataRetrievalFailureException("error");
			}
		});
	}
	catch (Exception ex) {
	}

	verify(localTransaction).begin();
	verify(interaction).close();
	verify(localTransaction).rollback();
	verify(connection).close();
}
 
Example #30
Source File: CciLocalTransactionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Test if a transaction ( begin / commit ) is executed on the
 * 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);

	CciLocalTransactionManager tm = new CciLocalTransactionManager();
	tm.setConnectionFactory(connectionFactory);
	TransactionTemplate tt = new TransactionTemplate(tm);

	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(connectionFactory));
			CciTemplate ct = new CciTemplate(connectionFactory);
			ct.execute(interactionSpec, record, record);
		}
	});

	verify(localTransaction).begin();
	verify(interaction).close();
	verify(localTransaction).commit();
	verify(connection).close();
}