Github user ijokarumawak commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1450#discussion_r104869088
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/pom.xml
 ---
    @@ -81,5 +81,17 @@
                 <artifactId>hamcrest-all</artifactId>
                 <version>1.3</version>
             </dependency>
    +        <dependency>
    +            <groupId>org.springframework</groupId>
    --- End diff --
    
    @mattyb149 @ToivoAdams 
    If we test JdbcTemplate works with DBCPService then need Spring JDBC for 
testing.
    
    However, if adding a test as an example showing the way to expose 
connection as DataSource, then it's not necessary. How about adding a test 
method like this?
    
    ```java
    /**
     * This is an example code for custom extensions using DBCPService and also 
a third party library
     * that requires {@link DataSource} instead of {@link Connection}, for 
example Spring JdbcTemplate.
     */
    @Test
    public void exampleExposeConnectionAsDataSource() throws 
InitializationException, SQLException {
        final TestRunner runner = 
TestRunners.newTestRunner(TestProcessor.class);
        final DBCPConnectionPool service = new DBCPConnectionPool();
        runner.addControllerService("test-good1", service);
    
        // remove previous test database, if any
        final File dbLocation = new File(DB_LOCATION);
        dbLocation.delete();
    
        // set embedded Derby database connection url
        runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, 
"jdbc:derby:" + DB_LOCATION + ";create=true");
        runner.setProperty(service, DBCPConnectionPool.DB_USER, "tester");
        runner.setProperty(service, DBCPConnectionPool.DB_PASSWORD, "testerp");
        runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, 
"org.apache.derby.jdbc.EmbeddedDriver");
    
        runner.enableControllerService(service);
    
        runner.assertValid(service);
        final DBCPService dbcpService = (DBCPService) 
runner.getProcessContext().getControllerServiceLookup().getControllerService("test-good1");
        Assert.assertNotNull(dbcpService);
    
        // Wrapping DBCPService with BasicDataSource, so that a library that 
requires DataSource can use
        // connections maintained by DBCPService.
        final DataSource dataSource = new BasicDataSource() {
            @Override
            public Connection getConnection() throws SQLException {
                return dbcpService.getConnection();
            }
        };
    
        final Connection connection = dataSource.getConnection();
        createInsertSelectDrop(connection);
    
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to