@Test public void testReadData() throws Exception { LogChannel log = mock( LogChannel.class ); when( repoMeta.getKettleUserRepositoriesFile() ).thenReturn( getClass().getResource( "repositories.xml" ).getPath() ); when( repoMeta.newLogChannel() ).thenReturn( log ); repoMeta.readData(); String repositoriesXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Const.CR + "<repositories>" + Const.CR + " <connection>" + Const.CR + " <name>local postgres</name>" + Const.CR + " <server>localhost</server>" + Const.CR + " <type>POSTGRESQL</type>" + Const.CR + " <access>Native</access>" + Const.CR + " <database>hibernate</database>" + Const.CR + " <port>5432</port>" + Const.CR + " <username>auser</username>" + Const.CR + " <password>Encrypted 2be98afc86aa7f285bb18bd63c99dbdde</password>" + Const.CR + " <servername/>" + Const.CR + " <data_tablespace/>" + Const.CR + " <index_tablespace/>" + Const.CR + " <attributes>" + Const.CR + " <attribute><code>FORCE_IDENTIFIERS_TO_LOWERCASE</code><attribute>N</attribute></attribute>" + Const.CR + " <attribute><code>FORCE_IDENTIFIERS_TO_UPPERCASE</code><attribute>N</attribute></attribute>" + Const.CR + " <attribute><code>IS_CLUSTERED</code><attribute>N</attribute></attribute>" + Const.CR + " <attribute><code>PORT_NUMBER</code><attribute>5432</attribute></attribute>" + Const.CR + " <attribute><code>PRESERVE_RESERVED_WORD_CASE</code><attribute>N</attribute></attribute>" + Const.CR + " <attribute><code>QUOTE_ALL_FIELDS</code><attribute>N</attribute></attribute>" + Const.CR + " <attribute><code>SUPPORTS_BOOLEAN_DATA_TYPE</code><attribute>Y</attribute></attribute>" + Const.CR + " <attribute><code>SUPPORTS_TIMESTAMP_DATA_TYPE</code><attribute>Y</attribute></attribute>" + Const.CR + " <attribute><code>USE_POOLING</code><attribute>N</attribute></attribute>" + Const.CR + " </attributes>" + Const.CR + " </connection>" + Const.CR + " <repository> <id>KettleFileRepository</id>" + Const.CR + " <name>Test Repository</name>" + Const.CR + " <description>Test Repository Description</description>" + Const.CR + " <is_default>false</is_default>" + Const.CR + " <base_directory>test-repository</base_directory>" + Const.CR + " <read_only>N</read_only>" + Const.CR + " <hides_hidden_files>N</hides_hidden_files>" + Const.CR + " </repository> </repositories>" + Const.CR; assertEquals( repositoriesXml, repoMeta.getXML() ); RepositoriesMeta clone = repoMeta.clone(); assertEquals( repositoriesXml, repoMeta.getXML() ); assertNotSame( clone, repoMeta ); assertEquals( 1, repoMeta.nrRepositories() ); RepositoryMeta repository = repoMeta.getRepository( 0 ); assertEquals( "Test Repository", repository.getName() ); assertEquals( "Test Repository Description", repository.getDescription() ); assertEquals( " <repository> <id>KettleFileRepository</id>" + Const.CR + " <name>Test Repository</name>" + Const.CR + " <description>Test Repository Description</description>" + Const.CR + " <is_default>false</is_default>" + Const.CR + " <base_directory>test-repository</base_directory>" + Const.CR + " <read_only>N</read_only>" + Const.CR + " <hides_hidden_files>N</hides_hidden_files>" + Const.CR + " </repository>", repository.getXML() ); assertSame( repository, repoMeta.searchRepository( "Test Repository" ) ); assertSame( repository, repoMeta.findRepositoryById( "KettleFileRepository" ) ); assertSame( repository, repoMeta.findRepository( "Test Repository" ) ); assertNull( repoMeta.findRepository( "not found" ) ); assertNull( repoMeta.findRepositoryById( "not found" ) ); assertEquals( 0, repoMeta.indexOfRepository( repository ) ); repoMeta.removeRepository( 0 ); assertEquals( 0, repoMeta.nrRepositories() ); assertNull( repoMeta.searchRepository( "Test Repository" ) ); repoMeta.addRepository( 0, repository ); assertEquals( 1, repoMeta.nrRepositories() ); repoMeta.removeRepository( 1 ); assertEquals( 1, repoMeta.nrRepositories() ); assertEquals( 1, repoMeta.nrDatabases() ); assertEquals( "local postgres", repoMeta.getDatabase( 0 ).getName() ); DatabaseMeta searchDatabase = repoMeta.searchDatabase( "local postgres" ); assertSame( searchDatabase, repoMeta.getDatabase( 0 ) ); assertEquals( 0, repoMeta.indexOfDatabase( searchDatabase ) ); repoMeta.removeDatabase( 0 ); assertEquals( 0, repoMeta.nrDatabases() ); assertNull( repoMeta.searchDatabase( "local postgres" ) ); repoMeta.addDatabase( 0, searchDatabase ); assertEquals( 1, repoMeta.nrDatabases() ); repoMeta.removeDatabase( 1 ); assertEquals( 1, repoMeta.nrDatabases() ); assertEquals( "Unable to read repository with id [junk]. RepositoryMeta is not available.", repoMeta.getErrorMessage() ); }
public boolean readData() throws KettleException { clear(); File file = new File( getKettleLocalRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file .getAbsolutePath() ) ); } file = new File( getKettleUserRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { return true; } } if ( log.isBasic() ) { log.logBasic( BaseMessages.getString( PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile() ) ); } try { DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; try { doc = db.parse( file ); } catch ( FileNotFoundException ef ) { InputStream is = getClass().getResourceAsStream( "/org/pentaho/di/repository/repositories.xml" ); if ( is != null ) { doc = db.parse( is ); } else { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.OpeningFile", file .getAbsoluteFile() ), ef ); } } parseRepositoriesDoc( doc ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.ReadingInfo" ), e ); } return true; }
RepositoriesMeta { public boolean readData() throws KettleException { clear(); File file = new File( getKettleLocalRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file .getAbsolutePath() ) ); } file = new File( getKettleUserRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { return true; } } if ( log.isBasic() ) { log.logBasic( BaseMessages.getString( PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile() ) ); } try { DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; try { doc = db.parse( file ); } catch ( FileNotFoundException ef ) { InputStream is = getClass().getResourceAsStream( "/org/pentaho/di/repository/repositories.xml" ); if ( is != null ) { doc = db.parse( is ); } else { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.OpeningFile", file .getAbsoluteFile() ), ef ); } } parseRepositoriesDoc( doc ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.ReadingInfo" ), e ); } return true; } }
RepositoriesMeta { public boolean readData() throws KettleException { clear(); File file = new File( getKettleLocalRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file .getAbsolutePath() ) ); } file = new File( getKettleUserRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { return true; } } if ( log.isBasic() ) { log.logBasic( BaseMessages.getString( PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile() ) ); } try { DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; try { doc = db.parse( file ); } catch ( FileNotFoundException ef ) { InputStream is = getClass().getResourceAsStream( "/org/pentaho/di/repository/repositories.xml" ); if ( is != null ) { doc = db.parse( is ); } else { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.OpeningFile", file .getAbsoluteFile() ), ef ); } } parseRepositoriesDoc( doc ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.ReadingInfo" ), e ); } return true; } RepositoriesMeta(); }
RepositoriesMeta { public boolean readData() throws KettleException { clear(); File file = new File( getKettleLocalRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file .getAbsolutePath() ) ); } file = new File( getKettleUserRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { return true; } } if ( log.isBasic() ) { log.logBasic( BaseMessages.getString( PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile() ) ); } try { DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; try { doc = db.parse( file ); } catch ( FileNotFoundException ef ) { InputStream is = getClass().getResourceAsStream( "/org/pentaho/di/repository/repositories.xml" ); if ( is != null ) { doc = db.parse( is ); } else { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.OpeningFile", file .getAbsoluteFile() ), ef ); } } parseRepositoriesDoc( doc ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.ReadingInfo" ), e ); } return true; } RepositoriesMeta(); void clear(); void addDatabase( DatabaseMeta ci ); void addRepository( RepositoryMeta ri ); void addDatabase( int p, DatabaseMeta ci ); void addRepository( int p, RepositoryMeta ri ); DatabaseMeta getDatabase( int i ); RepositoryMeta getRepository( int i ); void removeDatabase( int i ); void removeRepository( int i ); int nrDatabases(); int nrRepositories(); DatabaseMeta searchDatabase( String name ); RepositoryMeta searchRepository( String name ); int indexOfDatabase( DatabaseMeta di ); int indexOfRepository( RepositoryMeta ri ); RepositoryMeta findRepository( String name ); RepositoryMeta findRepositoryById( String id ); boolean readData(); void readDataFromInputStream( InputStream is ); String getXML(); void writeData(); String toString(); RepositoriesMeta clone(); String getErrorMessage(); LogChannelInterface getLog(); }
RepositoriesMeta { public boolean readData() throws KettleException { clear(); File file = new File( getKettleLocalRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { if ( log.isDetailed() ) { log.logDetailed( BaseMessages.getString( PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file .getAbsolutePath() ) ); } file = new File( getKettleUserRepositoriesFile() ); if ( !file.exists() || !file.isFile() ) { return true; } } if ( log.isBasic() ) { log.logBasic( BaseMessages.getString( PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile() ) ); } try { DocumentBuilderFactory dbf = XMLParserFactoryProducer.createSecureDocBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc; try { doc = db.parse( file ); } catch ( FileNotFoundException ef ) { InputStream is = getClass().getResourceAsStream( "/org/pentaho/di/repository/repositories.xml" ); if ( is != null ) { doc = db.parse( is ); } else { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.OpeningFile", file .getAbsoluteFile() ), ef ); } } parseRepositoriesDoc( doc ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "RepositoryMeta.Error.ReadingInfo" ), e ); } return true; } RepositoriesMeta(); void clear(); void addDatabase( DatabaseMeta ci ); void addRepository( RepositoryMeta ri ); void addDatabase( int p, DatabaseMeta ci ); void addRepository( int p, RepositoryMeta ri ); DatabaseMeta getDatabase( int i ); RepositoryMeta getRepository( int i ); void removeDatabase( int i ); void removeRepository( int i ); int nrDatabases(); int nrRepositories(); DatabaseMeta searchDatabase( String name ); RepositoryMeta searchRepository( String name ); int indexOfDatabase( DatabaseMeta di ); int indexOfRepository( RepositoryMeta ri ); RepositoryMeta findRepository( String name ); RepositoryMeta findRepositoryById( String id ); boolean readData(); void readDataFromInputStream( InputStream is ); String getXML(); void writeData(); String toString(); RepositoriesMeta clone(); String getErrorMessage(); LogChannelInterface getLog();  }