JcrBackedDatasourceMgmtService implements IDatasourceMgmtService { public String updateDatasourceByName( String name, IDatabaseConnection databaseConnection ) throws NonExistingDatasourceException, DatasourceMgmtServiceException { RepositoryFile file = null; try { if ( databaseConnection.getId() != null ) { file = repository.getFileById( databaseConnection.getId() ); } else { file = repository.getFile( getPath( name ) ); } } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage() ), ure ); } return updateDatasource( file, databaseConnection ); } 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 testUpdateDatasourceWithName() 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 ); doReturn( f ).when( repo ) .updateFile( any( RepositoryFile.class ), any( NodeRepositoryFileData.class ), anyString() ); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection databaseConnection = createDatabaseConnection( EXP_DBMETA_NAME ); updateDatabaseConnection( databaseConnection ); datasourceMgmtService.updateDatasourceByName( EXP_DBMETA_NAME, databaseConnection ); verify( repo ).updateFile( argThat( isLikeFile( new RepositoryFile.Builder( EXP_DBMETA_NAME + ".kdb" ).build() ) ), argThat( hasData( pathPropertyPair( "/databaseMeta/HOST_NAME", EXP_UPDATED_DBMETA_HOSTNAME ) ) ), anyString() ); }