@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(); }
/** * Close the given CCI Interaction and ignore any thrown exception. * This is useful for typical finally blocks in manual CCI code. * @param interaction the CCI Interaction to close * @see javax.resource.cci.Interaction#close() */ private void closeInteraction(@Nullable Interaction interaction) { if (interaction != null) { try { interaction.close(); } catch (ResourceException ex) { logger.trace("Could not close CCI Interaction", ex); } catch (Throwable ex) { // We don't trust the CCI driver: It might throw RuntimeException or Error. logger.trace("Unexpected exception on closing CCI Interaction", ex); } } }
/** * Close the given CCI Interaction and ignore any thrown exception. * This is useful for typical finally blocks in manual CCI code. * @param interaction the CCI Interaction to close * @see javax.resource.cci.Interaction#close() */ private void closeInteraction(@Nullable Interaction interaction) { if (interaction != null) { try { interaction.close(); } catch (ResourceException ex) { logger.trace("Could not close CCI Interaction", ex); } catch (Throwable ex) { // We don't trust the CCI driver: It might throw RuntimeException or Error. logger.trace("Unexpected exception on closing CCI Interaction", ex); } } }
@Test public void testSimpleRecordOperationWithInputOutputRecord() 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); SimpleRecordOperation query = new SimpleRecordOperation(connectionFactory, interactionSpec); given(connectionFactory.getConnection()).willReturn(connection); given(connection.createInteraction()).willReturn(interaction); given(interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord)).willReturn(true); query.execute(inputOutputRecord, inputOutputRecord); verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord); verify(interaction).close(); verify(connection).close(); }
@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(); }
@Test public void testSimpleRecordOperation() 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); SimpleRecordOperation query = new SimpleRecordOperation(connectionFactory, interactionSpec); given(connectionFactory.getConnection()).willReturn(connection); given(connection.createInteraction()).willReturn(interaction); given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord); query.execute(inputRecord); verify(interaction).execute(interactionSpec, inputRecord); verify(interaction).close(); verify(connection).close(); }
public void close() throws ResourceException { for (Object interaction : interactions) { ((Interaction) interaction).close(); } closed = true; }
@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(); }
public void close() throws ResourceException { for(int ii = 0; ii < interactions.size(); ii++) { ((Interaction)interactions.get(ii)).close(); } closed = true; }
public void testExecuteReturnsRecord() throws Exception { IndexedRecordInteraction indexedInteraction = new IndexedRecordInteraction(); TestRecord testRecord = new TestRecord(); indexedInteraction.setResponse(testRecord); mockFactory.getInteractionHandler().addImplementor(indexedInteraction); Interaction interaction = mockFactory.getMockConnectionFactory().getConnection().createInteraction(); assertSame(testRecord, interaction.execute(null, null)); List expectedList = new ArrayList(); expectedList.add("1"); indexedInteraction.setExpectedRequest(expectedList); assertNull(interaction.execute(null, null)); MappedRecordInteraction mappedInteraction = new MappedRecordInteraction(); TestRecord anotherTestRecord = new TestRecord(); mappedInteraction.setResponse(anotherTestRecord); Map expectedMap = new HashMap(); expectedMap.put("1", "1"); mappedInteraction.setExpectedRequest(expectedMap); MockMappedRecord actualRequest = new MockMappedRecord(); actualRequest.put("1", "1"); mockFactory.getInteractionHandler().addImplementor(mappedInteraction); assertSame(anotherTestRecord, interaction.execute(null, actualRequest)); }
@Test public void testSimpleRecordOperationWithExplicitOutputRecord() 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); SimpleRecordOperation operation = new SimpleRecordOperation(connectionFactory, interactionSpec); given(connectionFactory.getConnection()).willReturn(connection); given(connection.createInteraction()).willReturn(interaction); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); operation.execute(inputRecord, outputRecord); verify(interaction).execute(interactionSpec, inputRecord, outputRecord); verify(interaction).close(); verify(connection).close(); }
public void close() throws ResourceException { for(int ii = 0; ii < interactions.size(); ii++) { ((Interaction)interactions.get(ii)).close(); } closed = true; }
@Override public Message handle(Exchange exchange, Connection conn, Interaction interact) throws Exception { MappedRecord record = getRecordFactory().createMappedRecord(MappedRecordHandler.class.getName()); MappedRecord outRecord = (MappedRecord) interact.execute(getInteractionSpec(), getMessageComposer(MappedRecordBindingData.class).decompose(exchange, new MappedRecordBindingData(record)).getRecord()); return _composer.compose(new MappedRecordBindingData(outRecord), exchange); } }
@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(); }
/** * Close the given CCI Interaction and ignore any thrown exception. * This is useful for typical finally blocks in manual CCI code. * @param interaction the CCI Interaction to close * @see javax.resource.cci.Interaction#close() */ private void closeInteraction(@Nullable Interaction interaction) { if (interaction != null) { try { interaction.close(); } catch (ResourceException ex) { logger.trace("Could not close CCI Interaction", ex); } catch (Throwable ex) { // We don't trust the CCI driver: It might throw RuntimeException or Error. logger.trace("Unexpected exception on closing CCI Interaction", ex); } } }
@Override public Message handle(Exchange exchange, Connection conn, Interaction interact) throws Exception { IndexedRecord record = getRecordFactory().createIndexedRecord(IndexedRecordHandler.class.getName()); IndexedRecord outRecord = (IndexedRecord) interact.execute(getInteractionSpec(), getMessageComposer(IndexedRecordBindingData.class).decompose(exchange, new IndexedRecordBindingData(record)).getRecord()); return _composer.compose(new IndexedRecordBindingData(outRecord), exchange); } }