Search in sources :

Example 1 with JndiDataSourceFactory

use of nl.nn.adapterframework.jndi.JndiDataSourceFactory in project iaf by ibissource.

the class MessageStoreListenerTest method createListener.

@Override
public MessageStoreListener<M> createListener() throws Exception {
    MessageStoreListener listener = spy(new MessageStoreListener() {

        @Override
        protected Object getRawMessage(Connection conn, Map threadContext) throws ListenerException {
            // super class JdbcListener always wraps this in a MessageWrapper
            MessageWrapper<Object> mw = new MessageWrapper<>();
            mw.setMessage(Message.asMessage(threadContext.get(STUB_RESULT_KEY)));
            mw.setId("" + threadContext.get(PipeLineSession.originalMessageIdKey));
            return mw;
        }
    });
    DatabaseMetaData md = mock(DatabaseMetaData.class);
    doReturn("product").when(md).getDatabaseProductName();
    doReturn("version").when(md).getDatabaseProductVersion();
    Connection conn = mock(Connection.class);
    doReturn(md).when(conn).getMetaData();
    JndiDataSourceFactory factory = new JndiDataSourceFactory();
    DataSource dataSource = mock(DataSource.class);
    String dataSourceName = "myDummyDataSource";
    factory.add(dataSource, dataSourceName);
    listener.setDataSourceFactory(factory);
    doReturn(conn).when(dataSource).getConnection();
    listener.setConnectionsArePooled(false);
    listener.setDatasourceName(dataSourceName);
    doReturn(new GenericDbmsSupport()).when(listener).getDbmsSupport();
    return listener;
}
Also used : Connection(java.sql.Connection) GenericDbmsSupport(nl.nn.adapterframework.jdbc.dbms.GenericDbmsSupport) DatabaseMetaData(java.sql.DatabaseMetaData) DataSource(javax.sql.DataSource) ListenerException(nl.nn.adapterframework.core.ListenerException) MessageStoreListener(nl.nn.adapterframework.jdbc.MessageStoreListener) JndiDataSourceFactory(nl.nn.adapterframework.jndi.JndiDataSourceFactory) Map(java.util.Map)

Aggregations

Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Map (java.util.Map)1 DataSource (javax.sql.DataSource)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 MessageStoreListener (nl.nn.adapterframework.jdbc.MessageStoreListener)1 GenericDbmsSupport (nl.nn.adapterframework.jdbc.dbms.GenericDbmsSupport)1 JndiDataSourceFactory (nl.nn.adapterframework.jndi.JndiDataSourceFactory)1