@Test public void testConnectRepository() throws KettleException { JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration(); 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 ); jobExecutionConfiguration.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; } } ); 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() ); jobExecutionConfiguration.connectRepository( repositoriesMeta, "notFound", "username", "password" ); assertEquals( "Repository Changed", initialRepo, jobExecutionConfiguration.getRepository() ); jobExecutionConfiguration.connectRepository( repositoriesMeta, mockRepo, "username", "" ); assertEquals( "Repository Changed", initialRepo, jobExecutionConfiguration.getRepository() ); jobExecutionConfiguration.connectRepository( repositoriesMeta, mockRepo, "username", "password" ); assertEquals( "Repository didn't change", repository, jobExecutionConfiguration.getRepository() ); assertTrue( "Repository not connected", connectionSuccess[0] ); }
public Repository connectRepository( String repositoryName, String username, String password ) throws KettleException { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.getLog().setLogLevel( log.getLogLevel() ); try { repositoriesMeta.readData(); } catch ( Exception e ) { throw new KettleException( "Unable to get a list of repositories to locate repository '" + repositoryName + "'" ); } return connectRepository( repositoriesMeta, repositoryName, username, password ); }
JobExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( String repositoryName, String username, String password ) throws KettleException { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.getLog().setLogLevel( log.getLogLevel() ); try { repositoriesMeta.readData(); } catch ( Exception e ) { throw new KettleException( "Unable to get a list of repositories to locate repository '" + repositoryName + "'" ); } return connectRepository( repositoriesMeta, repositoryName, username, password ); } }
JobExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( String repositoryName, String username, String password ) throws KettleException { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.getLog().setLogLevel( log.getLogLevel() ); try { repositoriesMeta.readData(); } catch ( Exception e ) { throw new KettleException( "Unable to get a list of repositories to locate repository '" + repositoryName + "'" ); } return connectRepository( repositoriesMeta, repositoryName, username, password ); } JobExecutionConfiguration();  JobExecutionConfiguration( Node trecNode ); }
JobExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( String repositoryName, String username, String password ) throws KettleException { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.getLog().setLogLevel( log.getLogLevel() ); try { repositoriesMeta.readData(); } catch ( Exception e ) { throw new KettleException( "Unable to get a list of repositories to locate repository '" + repositoryName + "'" ); } return connectRepository( repositoriesMeta, repositoryName, username, password ); } JobExecutionConfiguration();  JobExecutionConfiguration( 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 ); Map<String, String> getVariables(); void setVariables( Map<String, String> variables ); void setVariables( VariableSpace space ); boolean isExecutingRemotely(); void setExecutingRemotely( boolean remoteExecution ); boolean isExecutingLocally(); void setExecutingLocally( boolean localExecution ); SlaveServer getRemoteServer(); void setRemoteServer( SlaveServer remoteServer ); void getUsedVariables( JobMeta jobMeta ); Date getReplayDate(); void setReplayDate( Date replayDate ); boolean isSafeModeEnabled(); void setSafeModeEnabled( boolean usingSafeMode ); @Override String getRunConfiguration(); @Override void setRunConfiguration( String runConfiguration ); LogLevel getLogLevel(); void setLogLevel( LogLevel logLevel ); String getXML(); Repository connectRepository( String repositoryName, String username, String password ); Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ); String[] getArgumentStrings(); Result getPreviousResult(); void setPreviousResult( Result previousResult ); Repository getRepository(); void setRepository( Repository repository ); boolean isClearingLog(); void setClearingLog( boolean clearingLog ); boolean isPassingExport(); void setPassingExport( boolean passingExport ); String getStartCopyName(); void setStartCopyName( String startCopyName ); int getStartCopyNr(); void setStartCopyNr( int startCopyNr ); boolean isGatheringMetrics(); void setGatheringMetrics( boolean gatheringMetrics ); void setExpandingRemoteJob( boolean expandingRemoteJob ); boolean isExpandingRemoteJob(); Map<String, String> getExtensionOptions(); void setExtensionOptions( Map<String, String> extensionOptions ); Long getPassedBatchId(); void setPassedBatchId( Long passedBatchId ); void getUsedArguments( JobMeta jobMeta, String[] commandLineArguments, IMetaStore metaStore ); }
JobExecutionConfiguration implements ExecutionConfiguration { public Repository connectRepository( String repositoryName, String username, String password ) throws KettleException { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.getLog().setLogLevel( log.getLogLevel() ); try { repositoriesMeta.readData(); } catch ( Exception e ) { throw new KettleException( "Unable to get a list of repositories to locate repository '" + repositoryName + "'" ); } return connectRepository( repositoriesMeta, repositoryName, username, password ); } JobExecutionConfiguration();  JobExecutionConfiguration( 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 ); Map<String, String> getVariables(); void setVariables( Map<String, String> variables ); void setVariables( VariableSpace space ); boolean isExecutingRemotely(); void setExecutingRemotely( boolean remoteExecution ); boolean isExecutingLocally(); void setExecutingLocally( boolean localExecution ); SlaveServer getRemoteServer(); void setRemoteServer( SlaveServer remoteServer ); void getUsedVariables( JobMeta jobMeta ); Date getReplayDate(); void setReplayDate( Date replayDate ); boolean isSafeModeEnabled(); void setSafeModeEnabled( boolean usingSafeMode ); @Override String getRunConfiguration(); @Override void setRunConfiguration( String runConfiguration ); LogLevel getLogLevel(); void setLogLevel( LogLevel logLevel ); String getXML(); Repository connectRepository( String repositoryName, String username, String password ); Repository connectRepository( RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password ); String[] getArgumentStrings(); Result getPreviousResult(); void setPreviousResult( Result previousResult ); Repository getRepository(); void setRepository( Repository repository ); boolean isClearingLog(); void setClearingLog( boolean clearingLog ); boolean isPassingExport(); void setPassingExport( boolean passingExport ); String getStartCopyName(); void setStartCopyName( String startCopyName ); int getStartCopyNr(); void setStartCopyNr( int startCopyNr ); boolean isGatheringMetrics(); void setGatheringMetrics( boolean gatheringMetrics ); void setExpandingRemoteJob( boolean expandingRemoteJob ); boolean isExpandingRemoteJob(); Map<String, String> getExtensionOptions(); void setExtensionOptions( Map<String, String> extensionOptions ); Long getPassedBatchId(); void setPassedBatchId( Long passedBatchId ); void getUsedArguments( JobMeta jobMeta, String[] commandLineArguments, IMetaStore metaStore ); static final String XML_TAG; }