JcrBackedDatasourceMgmtService implements IDatasourceMgmtService { public IDatabaseConnection getDatasourceByName( String name ) throws DatasourceMgmtServiceException { RepositoryFile file = null; try { file = repository.getFile( getPath( name ) ); } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages.getInstance().getErrorString( "DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", name, ure.getLocalizedMessage() ), ure ); } if ( file != null ) { return getDatasource( file ); } return null; } 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 testDatasourceNotFound() throws Exception { final String datasourceName = "not_here"; final String dotKdb = ".kdb"; final String fileName = datasourceName + dotKdb; final String databasesFolderPath = "/etc/pdi/databases"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); doReturn( new RepositoryFile.Builder( "123", "databases" ).folder( true ).build() ).when( repo ).getFile( databasesFolderPath ); doReturn( reservedChars ).when( repo ).getReservedChars(); doReturn( null ).when( repo ).getFile( databasesFolderPath + RepositoryFile.SEPARATOR + fileName ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); Assert.assertNull( datasourceMgmtService.getDatasourceByName( datasourceName ) ); }