javax.resource.cci.RecordFactory Java Examples
The following examples show how to use
javax.resource.cci.RecordFactory.
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: JCAMapper.java From hibersap with Apache License 2.0 | 6 votes |
public MappedRecord mapFunctionMapValuesToMappedRecord(final String bapiName, final RecordFactory recordFactory, final Map<String, Object> functionMap) throws ResourceException { LOG.debug("mapFunctionMapValuesToMappedRecord() functionMap=" + functionMap); MappedRecord mappedInputRecord = recordFactory.createMappedRecord(bapiName); final Map<String, Object> importMap = UnsafeCastHelper.castToMap(functionMap.get(BapiConstants.IMPORT)); mapToMappedRecord(recordFactory, mappedInputRecord, importMap); final Map<String, Object> changingMap = UnsafeCastHelper.castToMap(functionMap.get(BapiConstants.CHANGING)); mapToMappedRecord(recordFactory, mappedInputRecord, changingMap); final Map<String, Object> tableMap = UnsafeCastHelper.castToMap(functionMap.get(TABLE)); mapToMappedRecord(recordFactory, mappedInputRecord, tableMap); LOG.debug("mapFunctionMapValuesToMappedRecord() record=" + mappedInputRecord); return mappedInputRecord; }
Example #2
Source File: CciTemplate.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Execute the specified interaction on an EIS with CCI. * All other interaction execution methods go through this. * @param spec the CCI InteractionSpec instance that defines * the interaction (connector-specific) * @param inputRecord the input record * @param outputRecord output record (can be {@code null}) * @param outputExtractor object to convert the output record to a result object * @return the output data extracted with the RecordExtractor object * @throws DataAccessException if there is any problem */ protected <T> T doExecute( final InteractionSpec spec, final Record inputRecord, final Record outputRecord, final RecordExtractor<T> outputExtractor) throws DataAccessException { return execute(new InteractionCallback<T>() { @Override public T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory) throws ResourceException, SQLException, DataAccessException { Record outputRecordToUse = outputRecord; try { if (outputRecord != null || getOutputRecordCreator() != null) { // Use the CCI execute method with output record as parameter. if (outputRecord == null) { RecordFactory recordFactory = getRecordFactory(connectionFactory); outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory); } interaction.execute(spec, inputRecord, outputRecordToUse); } else { outputRecordToUse = interaction.execute(spec, inputRecord); } return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null); } finally { if (outputRecordToUse instanceof ResultSet) { closeResultSet((ResultSet) outputRecordToUse); } } } }); }
Example #3
Source File: CciTemplateTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCreateIndexedRecord() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); IndexedRecord indexedRecord = mock(IndexedRecord.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(recordFactory.createIndexedRecord("name")).willReturn(indexedRecord); CciTemplate ct = new CciTemplate(connectionFactory); ct.createIndexedRecord("name"); verify(recordFactory).createIndexedRecord("name"); }
Example #4
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCreateIndexedRecord() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); IndexedRecord indexedRecord = mock(IndexedRecord.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(recordFactory.createIndexedRecord("name")).willReturn(indexedRecord); CciTemplate ct = new CciTemplate(connectionFactory); ct.createIndexedRecord("name"); verify(recordFactory).createIndexedRecord("name"); }
Example #5
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCreateMappedRecord() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); MappedRecord mappedRecord = mock(MappedRecord.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(recordFactory.createMappedRecord("name")).willReturn(mappedRecord); CciTemplate ct = new CciTemplate(connectionFactory); ct.createMappedRecord("name"); verify(recordFactory).createMappedRecord("name"); }
Example #6
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testTemplateExecuteWithCreatorAndRecordFactoryNotSupported() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.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()).willThrow(new NotSupportedException("not supported")); given(connection.createInteraction()).willReturn(interaction); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(new RecordCreator() { @Override public Record createRecord(RecordFactory recordFactory) { assertTrue(recordFactory instanceof NotSupportedRecordFactory); return outputRecord; } }); ct.execute(interactionSpec, inputRecord); verify(interaction).execute(interactionSpec, inputRecord, outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #7
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@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(); }
Example #8
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Test public void testTemplateExecuteInputExtractorTrueWithCreator() throws ResourceException, SQLException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.class); RecordExtractor<Object> extractor = mock(RecordExtractor.class); RecordCreator creator = mock(RecordCreator.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(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(creator.createRecord(recordFactory)).willReturn(outputRecord); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); given(extractor.extractData(outputRecord)).willReturn(new Object()); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(creator); ct.execute(interactionSpec, inputRecord, extractor); verify(extractor).extractData(outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #9
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testTemplateExecuteInputGeneratorTrueWithCreator() throws ResourceException { 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); RecordCreator creator = mock(RecordCreator.class); Record inputRecord = mock(Record.class); Record outputRecord = mock(Record.class); InteractionSpec interactionSpec = mock(InteractionSpec.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(generator.createRecord(recordFactory)).willReturn(inputRecord); given(connectionFactory.getConnection()).willReturn(connection); given(connection.createInteraction()).willReturn(interaction); given(creator.createRecord(recordFactory)).willReturn(outputRecord); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(creator); ct.execute(interactionSpec, generator); verify(interaction).execute(interactionSpec, inputRecord, outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #10
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testTemplateExecuteInputGeneratorFalse() throws ResourceException { 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); 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); CciTemplate ct = new CciTemplate(connectionFactory); ct.execute(interactionSpec, generator); verify(interaction).execute(interactionSpec, inputRecord); verify(interaction).close(); verify(connection).close(); }
Example #11
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@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(); }
Example #12
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@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 #13
Source File: CciTemplateTests.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Test public void testTemplateExecuteInputOutputResultsSetFalse() throws ResourceException, SQLException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.class); Record record = mock(Record.class); ResultSet resultset = mock(ResultSet.class); RecordCreator generator = mock(RecordCreator.class); RecordExtractor<Object> extractor = mock(RecordExtractor.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(record); given(interaction.execute(interactionSpec, record)).willReturn(resultset); given(extractor.extractData(resultset)).willReturn(new Object()); CciTemplate ct = new CciTemplate(connectionFactory); ct.execute(interactionSpec, generator, extractor); verify(extractor).extractData(resultset); verify(resultset).close(); verify(interaction).close(); verify(connection).close(); }
Example #14
Source File: MappingCommAreaOperation.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected final Record createInputRecord(RecordFactory recordFactory, Object inObject) { try { return new CommAreaRecord(objectToBytes(inObject)); } catch (IOException ex) { throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); } }
Example #15
Source File: CciTemplate.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Execute the specified interaction on an EIS with CCI. * All other interaction execution methods go through this. * @param spec the CCI InteractionSpec instance that defines * the interaction (connector-specific) * @param inputRecord the input record * @param outputRecord output record (can be {@code null}) * @param outputExtractor object to convert the output record to a result object * @return the output data extracted with the RecordExtractor object * @throws DataAccessException if there is any problem */ protected <T> T doExecute( final InteractionSpec spec, final Record inputRecord, final Record outputRecord, final RecordExtractor<T> outputExtractor) throws DataAccessException { return execute(new InteractionCallback<T>() { @Override public T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory) throws ResourceException, SQLException, DataAccessException { Record outputRecordToUse = outputRecord; try { if (outputRecord != null || getOutputRecordCreator() != null) { // Use the CCI execute method with output record as parameter. if (outputRecord == null) { RecordFactory recordFactory = getRecordFactory(connectionFactory); outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory); } interaction.execute(spec, inputRecord, outputRecordToUse); } else { outputRecordToUse = interaction.execute(spec, inputRecord); } return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null); } finally { if (outputRecordToUse instanceof ResultSet) { closeResultSet((ResultSet) outputRecordToUse); } } } }); }
Example #16
Source File: MappingCommAreaOperation.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected final Record createInputRecord(RecordFactory recordFactory, Object inObject) { try { return new CommAreaRecord(objectToBytes(inObject)); } catch (IOException ex) { throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); } }
Example #17
Source File: MappingCommAreaOperation.java From spring-analysis-note with MIT License | 5 votes |
@Override protected final Record createInputRecord(RecordFactory recordFactory, Object inObject) { try { return new CommAreaRecord(objectToBytes(inObject)); } catch (IOException ex) { throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); } }
Example #18
Source File: EisOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); verify(interaction).close(); verify(connection).close(); }
Example #19
Source File: EisOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); verify(interaction).close(); verify(connection).close(); }
Example #20
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCreateIndexedRecord() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); IndexedRecord indexedRecord = mock(IndexedRecord.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(recordFactory.createIndexedRecord("name")).willReturn(indexedRecord); CciTemplate ct = new CciTemplate(connectionFactory); ct.createIndexedRecord("name"); verify(recordFactory).createIndexedRecord("name"); }
Example #21
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCreateMappedRecord() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); MappedRecord mappedRecord = mock(MappedRecord.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(recordFactory.createMappedRecord("name")).willReturn(mappedRecord); CciTemplate ct = new CciTemplate(connectionFactory); ct.createMappedRecord("name"); verify(recordFactory).createMappedRecord("name"); }
Example #22
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testTemplateExecuteWithCreatorAndRecordFactoryNotSupported() throws ResourceException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.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()).willThrow(new NotSupportedException("not supported")); given(connection.createInteraction()).willReturn(interaction); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(new RecordCreator() { @Override public Record createRecord(RecordFactory recordFactory) { assertTrue(recordFactory instanceof NotSupportedRecordFactory); return outputRecord; } }); ct.execute(interactionSpec, inputRecord); verify(interaction).execute(interactionSpec, inputRecord, outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #23
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #24
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testTemplateExecuteInputExtractorTrueWithCreator() throws ResourceException, SQLException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.class); RecordExtractor<Object> extractor = mock(RecordExtractor.class); RecordCreator creator = mock(RecordCreator.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(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(creator.createRecord(recordFactory)).willReturn(outputRecord); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); given(extractor.extractData(outputRecord)).willReturn(new Object()); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(creator); ct.execute(interactionSpec, inputRecord, extractor); verify(extractor).extractData(outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #25
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testTemplateExecuteInputGeneratorTrueWithCreator() throws ResourceException { 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); RecordCreator creator = mock(RecordCreator.class); Record inputRecord = mock(Record.class); Record outputRecord = mock(Record.class); InteractionSpec interactionSpec = mock(InteractionSpec.class); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(generator.createRecord(recordFactory)).willReturn(inputRecord); given(connectionFactory.getConnection()).willReturn(connection); given(connection.createInteraction()).willReturn(interaction); given(creator.createRecord(recordFactory)).willReturn(outputRecord); given(connectionFactory.getRecordFactory()).willReturn(recordFactory); given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true); CciTemplate ct = new CciTemplate(connectionFactory); ct.setOutputRecordCreator(creator); ct.execute(interactionSpec, generator); verify(interaction).execute(interactionSpec, inputRecord, outputRecord); verify(interaction).close(); verify(connection).close(); }
Example #26
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testTemplateExecuteInputGeneratorFalse() throws ResourceException { 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); 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); CciTemplate ct = new CciTemplate(connectionFactory); ct.execute(interactionSpec, generator); verify(interaction).execute(interactionSpec, inputRecord); verify(interaction).close(); verify(connection).close(); }
Example #27
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #28
Source File: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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: CciTemplateTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testTemplateExecuteInputOutputResultsSetFalse() throws ResourceException, SQLException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RecordFactory recordFactory = mock(RecordFactory.class); Connection connection = mock(Connection.class); Interaction interaction = mock(Interaction.class); Record record = mock(Record.class); ResultSet resultset = mock(ResultSet.class); RecordCreator generator = mock(RecordCreator.class); RecordExtractor<Object> extractor = mock(RecordExtractor.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(record); given(interaction.execute(interactionSpec, record)).willReturn(resultset); given(extractor.extractData(resultset)).willReturn(new Object()); CciTemplate ct = new CciTemplate(connectionFactory); ct.execute(interactionSpec, generator, extractor); verify(extractor).extractData(resultset); verify(resultset).close(); verify(interaction).close(); verify(connection).close(); }
Example #30
Source File: JCAMapper.java From hibersap with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void mapToMappedRecord(final RecordFactory recordFactory, final Record record, final Map<String, Object> map) throws ResourceException { for (final String fieldName : map.keySet()) { final Object value = map.get(fieldName); if (Map.class.isAssignableFrom(value.getClass())) { final Map<String, Object> structureMap = UnsafeCastHelper.castToMap(value); final Record structure = recordFactory.createMappedRecord(fieldName); appendToRecord(record, fieldName, structure); mapToMappedRecord(recordFactory, structure, structureMap); } else if (Collection.class.isAssignableFrom(value.getClass())) { final Collection<Map<String, Object>> tableMap = UnsafeCastHelper.castToCollectionOfMaps(value); final IndexedRecord table = recordFactory.createIndexedRecord(fieldName); appendToRecord(record, fieldName, table); int i = 0; for (final Map<String, Object> row : tableMap) { MappedRecord rowRecord = recordFactory.createMappedRecord(fieldName + ":row:" + i); mapToMappedRecord(recordFactory, rowRecord, row); table.add(rowRecord); i++; } } else { appendToRecord(record, fieldName, value); } } }