JcrBackedDatasourceMgmtService implements IDatasourceMgmtService { public String createDatasource( IDatabaseConnection databaseConnection ) throws DuplicateDatasourceException, DatasourceMgmtServiceException { try { RepositoryFile file = new RepositoryFile.Builder( RepositoryFilenameUtils.escape( databaseConnection.getName() + RepositoryObjectType.DATABASE.getExtension(), cachedReservedChars ) ).title( RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName() ).versioned( true ).build(); file = repository.createFile( getDatabaseParentFolderId(), file, new NodeRepositoryFileData( databaseHelper .databaseConnectionToDataNode( databaseConnection ) ), null ); if ( file != null && file.getId() != null ) { return file.getId().toString(); } else { return null; } } catch ( UnifiedRepositoryException ure ) { if ( ure.getCause().toString().contains( "ItemExistsException" ) ) { throw new DuplicateDatasourceException(); } throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), 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 testCreateDatasource() throws Exception { final String parentFolderId = "123"; IUnifiedRepository repo = mock( IUnifiedRepository.class ); doReturn( new RepositoryFile.Builder( parentFolderId, "databases" ).folder( true ).build() ).when( repo ).getFile( "/etc/pdi/databases" ); doReturn( reservedChars ).when( repo ).getReservedChars(); IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService( repo, new DatabaseDialectService() ); IDatabaseConnection databaseConnection = createDatabaseConnection( EXP_DBMETA_NAME ); datasourceMgmtService.createDatasource( databaseConnection ); verify( repo ).createFile( eq( parentFolderId ), argThat( isLikeFile( new RepositoryFile.Builder( EXP_DBMETA_NAME + ".kdb" ).build() ) ), argThat( hasData( pathPropertyPair( "/databaseMeta/HOST_NAME", EXP_DBMETA_HOSTNAME ) ) ), anyString() ); }