@Test public void testConnectRepository() throws KettleException { TransExecutionConfiguration transExecConf = new TransExecutionConfiguration(); final RepositoriesMeta repositoriesMeta = mock( RepositoriesMeta.class ); final RepositoryMeta repositoryMeta = mock( RepositoryMeta.class ); final Repository repository = mock( Repository.class ); final String mockRepo = "mockRepo"; final boolean[] connectionSuccess = { false }; Repository initialRepo = mock( Repository.class ); transExecConf.setRepository( initialRepo ); KettleLogStore.init(); MockRepositoryPlugin mockRepositoryPlugin = mock( MockRepositoryPlugin.class ); when( mockRepositoryPlugin.getIds() ).thenReturn( new String[] { "mockRepo" } ); when( mockRepositoryPlugin.matches( "mockRepo" ) ).thenReturn( true ); when( mockRepositoryPlugin.getName() ).thenReturn( "mock-repository" ); when( mockRepositoryPlugin.getClassMap() ).thenAnswer( new Answer<Map<Class<?>, String>>() { @Override public Map<Class<?>, String> answer( InvocationOnMock invocation ) throws Throwable { Map<Class<?>, String> dbMap = new HashMap<Class<?>, String>(); dbMap.put( Repository.class, repositoryMeta.getClass().getName() ); return dbMap; } } ); List<PluginInterface> registeredPlugins = PluginRegistry.getInstance().getPlugins( RepositoryPluginType.class ); for ( PluginInterface registeredPlugin : registeredPlugins ) { PluginRegistry.getInstance().removePlugin( RepositoryPluginType.class, registeredPlugin ); } PluginRegistry.getInstance().registerPlugin( RepositoryPluginType.class, mockRepositoryPlugin ); when( repositoriesMeta.findRepository( anyString() ) ).thenAnswer( new Answer<RepositoryMeta>() { @Override public RepositoryMeta answer( InvocationOnMock invocation ) throws Throwable { return mockRepo.equals( invocation.getArguments()[0] ) ? repositoryMeta : null; } } ); when( mockRepositoryPlugin.loadClass( Repository.class ) ).thenReturn( repository ); doAnswer( new Answer() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable { if ( "username".equals( invocation.getArguments()[0] ) && "password".equals( invocation.getArguments()[1] ) ) { connectionSuccess[0] = true; } else { connectionSuccess[0] = false; throw new KettleException( "Mock Repository connection failed" ); } return null; } } ).when( repository ).connect( anyString(), anyString() ); transExecConf.connectRepository( repositoriesMeta, "notFound", "username", "password" ); assertEquals( "Repository Changed", initialRepo, transExecConf.getRepository() ); transExecConf.connectRepository( repositoriesMeta, mockRepo, "username", "" ); assertEquals( "Repository Changed", initialRepo, transExecConf.getRepository() ); transExecConf.connectRepository( repositoriesMeta, mockRepo, "username", "password" ); assertEquals( "Repository didn't change", repository, transExecConf.getRepository() ); assertTrue( "Repository not connected", connectionSuccess[0] ); }
public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException { RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" ); return null; } Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); if ( rep == null ) { log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" ); return null; } rep.init( repositoryMeta ); try { rep.connect( username, password ); setRepository( rep ); return rep; } catch ( Exception e ) { log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" ); return null; } }
TransExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException { RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" ); return null; } Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); if ( rep == null ) { log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" ); return null; } rep.init( repositoryMeta ); try { rep.connect( username, password ); setRepository( rep ); return rep; } catch ( Exception e ) { log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" ); return null; } } }
TransExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException { RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" ); return null; } Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); if ( rep == null ) { log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" ); return null; } rep.init( repositoryMeta ); try { rep.connect( username, password ); setRepository( rep ); return rep; } catch ( Exception e ) { log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" ); return null; } } TransExecutionConfiguration();  TransExecutionConfiguration( Node trecNode ); }
TransExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException { RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" ); return null; } Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); if ( rep == null ) { log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" ); return null; } rep.init( repositoryMeta ); try { rep.connect( username, password ); setRepository( rep ); return rep; } catch ( Exception e ) { log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" ); return null; } } TransExecutionConfiguration();  TransExecutionConfiguration( Node trecNode ); Object clone(); Map<String, String> getArguments(); void setArguments( Map<String, String> arguments ); void setParams( Map<String, String> params ); Map<String, String> getParams(); void setArgumentStrings( String[] arguments ); boolean isExecutingClustered(); void setExecutingClustered( boolean clusteredExecution ); boolean isClusterStarting(); void setClusterStarting( boolean notExecuting ); boolean isClusterShowingTransformation(); void setClusterShowingTransformation( boolean showingTransformations ); Map<String, String> getVariables(); void setVariables( Map<String, String> variables ); void setVariables( VariableSpace space ); boolean isExecutingRemotely(); void setExecutingRemotely( boolean remoteExecution ); boolean isClusterPosting(); void setClusterPosting( boolean clusterPosting ); boolean isExecutingLocally(); void setExecutingLocally( boolean localExecution ); boolean isClusterPreparing(); void setClusterPreparing( boolean clusterPreparing ); SlaveServer getRemoteServer(); void setRemoteServer( SlaveServer remoteServer ); void getAllVariables( TransMeta transMeta ); void getUsedVariables( TransMeta transMeta ); void getUsedArguments( TransMeta transMeta, String[] commandLineArguments ); Date getReplayDate(); void setReplayDate( Date replayDate ); boolean isSafeModeEnabled(); void setSafeModeEnabled( boolean usingSafeMode ); LogLevel getLogLevel(); void setLogLevel( LogLevel logLevel ); String getXML(); Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ); String[] getArgumentStrings(); TransDebugMeta getTransDebugMeta(); void setTransDebugMeta( TransDebugMeta transDebugMeta ); Result getPreviousResult(); void setPreviousResult( Result previousResult ); Repository getRepository(); void setRepository( Repository repository ); boolean isClearingLog(); void setClearingLog( boolean clearingLog ); boolean isPassingExport(); void setPassingExport( boolean passingExport ); boolean isGatheringMetrics(); void setGatheringMetrics( boolean gatheringMetrics ); boolean isShowingSubComponents(); void setShowingSubComponents( boolean showingSubComponents ); boolean isSetLogfile(); void setSetLogfile( boolean setLogfile ); boolean isSetAppendLogfile(); void setSetAppendLogfile( boolean setAppendLogfile ); String getLogFileName(); void setLogFileName( String fileName ); boolean isCreateParentFolder(); void setCreateParentFolder( boolean createParentFolder ); Long getPassedBatchId(); void setPassedBatchId( Long passedBatchId ); String getRunConfiguration(); void setRunConfiguration( String runConfiguration ); boolean isLogRemoteExecutionLocally(); void setLogRemoteExecutionLocally( boolean logRemoteExecutionLocally ); }
TransExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ) throws KettleException { RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { log.logBasic( "I couldn't find the repository with name '" + repositoryName + "'" ); return null; } Repository rep = PluginRegistry.getInstance().loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); if ( rep == null ) { log.logBasic( "Unable to load repository plugin for '" + repositoryName + "'" ); return null; } rep.init( repositoryMeta ); try { rep.connect( username, password ); setRepository( rep ); return rep; } catch ( Exception e ) { log.logBasic( "Unable to connect to the repository with name '" + repositoryName + "'" ); return null; } } TransExecutionConfiguration();  TransExecutionConfiguration( Node trecNode ); Object clone(); Map<String, String> getArguments(); void setArguments( Map<String, String> arguments ); void setParams( Map<String, String> params ); Map<String, String> getParams(); void setArgumentStrings( String[] arguments ); boolean isExecutingClustered(); void setExecutingClustered( boolean clusteredExecution ); boolean isClusterStarting(); void setClusterStarting( boolean notExecuting ); boolean isClusterShowingTransformation(); void setClusterShowingTransformation( boolean showingTransformations ); Map<String, String> getVariables(); void setVariables( Map<String, String> variables ); void setVariables( VariableSpace space ); boolean isExecutingRemotely(); void setExecutingRemotely( boolean remoteExecution ); boolean isClusterPosting(); void setClusterPosting( boolean clusterPosting ); boolean isExecutingLocally(); void setExecutingLocally( boolean localExecution ); boolean isClusterPreparing(); void setClusterPreparing( boolean clusterPreparing ); SlaveServer getRemoteServer(); void setRemoteServer( SlaveServer remoteServer ); void getAllVariables( TransMeta transMeta ); void getUsedVariables( TransMeta transMeta ); void getUsedArguments( TransMeta transMeta, String[] commandLineArguments ); Date getReplayDate(); void setReplayDate( Date replayDate ); boolean isSafeModeEnabled(); void setSafeModeEnabled( boolean usingSafeMode ); LogLevel getLogLevel(); void setLogLevel( LogLevel logLevel ); String getXML(); Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ); String[] getArgumentStrings(); TransDebugMeta getTransDebugMeta(); void setTransDebugMeta( TransDebugMeta transDebugMeta ); Result getPreviousResult(); void setPreviousResult( Result previousResult ); Repository getRepository(); void setRepository( Repository repository ); boolean isClearingLog(); void setClearingLog( boolean clearingLog ); boolean isPassingExport(); void setPassingExport( boolean passingExport ); boolean isGatheringMetrics(); void setGatheringMetrics( boolean gatheringMetrics ); boolean isShowingSubComponents(); void setShowingSubComponents( boolean showingSubComponents ); boolean isSetLogfile(); void setSetLogfile( boolean setLogfile ); boolean isSetAppendLogfile(); void setSetAppendLogfile( boolean setAppendLogfile ); String getLogFileName(); void setLogFileName( String fileName ); boolean isCreateParentFolder(); void setCreateParentFolder( boolean createParentFolder ); Long getPassedBatchId(); void setPassedBatchId( Long passedBatchId ); String getRunConfiguration(); void setRunConfiguration( String runConfiguration ); boolean isLogRemoteExecutionLocally(); void setLogRemoteExecutionLocally( boolean logRemoteExecutionLocally ); static final String XML_TAG; }