Tomcat9DbcpDatasourceAccessor implements DatasourceAccessor { @Override public DataSourceInfo getInfo(Object resource) throws Exception { DataSourceInfo dataSourceInfo = null; if (canMap(resource)) { BasicDataSource source = (BasicDataSource) resource; dataSourceInfo = new DataSourceInfo(); dataSourceInfo.setBusyConnections(source.getNumActive()); dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive()); dataSourceInfo.setMaxConnections(source.getMaxTotal()); dataSourceInfo.setJdbcUrl(source.getUrl()); dataSourceInfo.setUsername(source.getUsername()); dataSourceInfo.setResettable(false); dataSourceInfo.setType("tomcat-dbcp2"); } return dataSourceInfo; }  @Override DataSourceInfo getInfo(Object resource); @Override boolean reset(Object resource); @Override boolean canMap(Object resource);  }
@Test public void Tomcat9DbcpDatasourceAccessor() throws Exception { Tomcat9DbcpDatasourceAccessor accessor = new Tomcat9DbcpDatasourceAccessor(); try (BasicDataSource source = new BasicDataSource()) { assertEquals("tomcat-dbcp2", accessor.getInfo(source).getType()); } }
@Test public void Tomcat9DbcpDatasourceAccessorInvalid() throws Exception { Tomcat9DbcpDatasourceAccessor accessor = new Tomcat9DbcpDatasourceAccessor(); assertNull(accessor.getInfo(new Object())); }