JcrBackedDatasourceMgmtService implements IDatasourceMgmtService { public List<IDatabaseConnection> getDatasources() throws DatasourceMgmtServiceException { try { List<IDatabaseConnection> datasourceList = new ArrayList<IDatabaseConnection>(); List<RepositoryFile> repositoryFiles = getRepositoryFiles(); if ( repositoryFiles != null ) { for ( RepositoryFile file : repositoryFiles ) { NodeRepositoryFileData data = repository.getDataForRead( file.getId(), NodeRepositoryFileData.class ); IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection( file.getId(), file.getTitle(), data.getNode() ); datasourceList.add( databaseConnection ); } } return datasourceList; } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages.getInstance().getErrorString( "DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", ure.getLocalizedMessage() ), ure ); } } JcrBackedDatasourceMgmtService();  JcrBackedDatasourceMgmtService( IUnifiedRepository repository, IDatabaseDialectService databaseDialectService ); void init( IPentahoSession session ); String createDatasource( IDatabaseConnection databaseConnection ); void deleteDatasourceByName( String name ); void deleteDatasourceById( String id ); IDatabaseConnection getDatasourceByName( String name ); IDatabaseConnection getDatasourceById( String id ); List<IDatabaseConnection> getDatasources(); List<String> getDatasourceIds(); String updateDatasourceById( String id, IDatabaseConnection databaseConnection ); String updateDatasourceByName( String name, IDatabaseConnection databaseConnection );  }
@Test public void testGetDatasources() throws Exception { final String fileId = "456"; final String databasesFolderPath = "/etc/pdi/databases"; final String dotKdb = ".kdb"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); doReturn( new RepositoryFile.Builder( "123", "databases" ).folder( true ).build() ).when( repo ).getFile( databasesFolderPath ); doReturn( reservedChars ).when( repo ).getReservedChars(); RepositoryFile f = new RepositoryFile.Builder( fileId, EXP_DBMETA_NAME + dotKdb ).path( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ).build(); doReturn( f ).when( repo ).getFile( databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb ); final String EXP_HOST_NAME = "hello"; DataNode rootNode = new DataNode( "databaseMeta" ); rootNode.setProperty( "TYPE", "Hypersonic" ); rootNode.setProperty( "HOST_NAME", EXP_HOST_NAME ); rootNode.addNode( "attributes" ); doReturn( new NodeRepositoryFileData( rootNode ) ).when( repo ).getDataForRead( eq( fileId ), eq( NodeRepositoryFileData.class ) ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName( EXP_DBMETA_NAME ); assertEquals( EXP_HOST_NAME, conn.getHostname() ); }