public static void copyInternalJobVariables( JobMeta sourceJobMeta, TransMeta targetTransMeta ) { // Also set some internal JOB variables... // String[] internalVariables = Const.INTERNAL_JOB_VARIABLES; for ( String variableName : internalVariables ) { targetTransMeta.setVariable( variableName, sourceJobMeta.getVariable( variableName ) ); } }
public void getUsedVariables( JobMeta jobMeta ) { Properties sp = new Properties(); VariableSpace space = Variables.getADefaultVariableSpace(); String[] keys = space.listVariables(); for ( int i = 0; i < keys.length; i++ ) { sp.put( keys[i], space.getVariable( keys[i] ) ); } List<String> vars = jobMeta.getUsedVariables(); if ( vars != null && vars.size() > 0 ) { HashMap<String, String> newVariables = new HashMap<String, String>(); for ( int i = 0; i < vars.size(); i++ ) { String varname = vars.get( i ); if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) { // add all new non-internal variables to newVariablesMap newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) ); } } // variables.clear(); variables.putAll( newVariables ); } // Also add the internal job variables if these are set... // for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) { String value = jobMeta.getVariable( variableName ); if ( !Utils.isEmpty( value ) ) { variables.put( variableName, value ); } } }
@Test public void testGetUsedVariablesWithSamePreviousExecutionConfigurationVariables() throws KettleException { JobExecutionConfiguration executionConfiguration = new JobExecutionConfiguration(); Map<String, String> variables0 = new HashMap<>(); variables0.put( "var1", "valueVar1" ); executionConfiguration.setVariables( variables0 ); JobMeta jobMeta0 = mock( JobMeta.class ); List<String> list0 = new ArrayList<String>(); list0.add( "var1" ); when( jobMeta0.getUsedVariables( ) ).thenReturn( list0 ); when( jobMeta0.getVariable( anyString() ) ).thenReturn( "internalDummyValue" ); executionConfiguration.getUsedVariables( jobMeta0 ); // 8 = 7 internalDummyValues + var1 from JobMeta ( with variables0 value ) assertEquals( 8, executionConfiguration.getVariables().size() ); assertEquals( "valueVar1", executionConfiguration.getVariables().get( "var1" ) ); }
@Test public void testGetUsedVariablesWithNoPreviousExecutionConfigurationVariables() throws KettleException { JobExecutionConfiguration executionConfiguration = new JobExecutionConfiguration(); Map<String, String> variables0 = new HashMap<>(); executionConfiguration.setVariables( variables0 ); JobMeta jobMeta0 = mock( JobMeta.class ); List<String> list0 = new ArrayList<String>(); list0.add( "var1" ); when( jobMeta0.getUsedVariables( ) ).thenReturn( list0 ); // Const.INTERNAL_VARIABLE_PREFIX values when( jobMeta0.getVariable( anyString() ) ).thenReturn( "internalDummyValue" ); executionConfiguration.getUsedVariables( jobMeta0 ); // 8 = 7 internalDummyValues + var1 from JobMeta with default value assertEquals( 8, executionConfiguration.getVariables().size() ); assertEquals( "", executionConfiguration.getVariables().get( "var1" ) ); }
@Test public void testGetUsedVariablesWithDifferentPreviousExecutionConfigurationVariables() throws KettleException { JobExecutionConfiguration executionConfiguration = new JobExecutionConfiguration(); Map<String, String> variables0 = new HashMap<>(); variables0.put( "var2", "valueVar2" ); executionConfiguration.setVariables( variables0 ); JobMeta jobMeta0 = mock( JobMeta.class ); List<String> list0 = new ArrayList<String>(); list0.add( "var1" ); when( jobMeta0.getUsedVariables( ) ).thenReturn( list0 ); when( jobMeta0.getVariable( anyString() ) ).thenReturn( "internalDummyValue" ); executionConfiguration.getUsedVariables( jobMeta0 ); // 9 = 7 internalDummyValues + var1 from JobMeta ( with the default value ) + var2 from variables0 assertEquals( 9, executionConfiguration.getVariables().size() ); assertEquals( "", executionConfiguration.getVariables().get( "var1" ) ); assertEquals( "valueVar2", executionConfiguration.getVariables().get( "var2" ) ); }
@Test public void testUpdateCurrentDirWithRepository( ) { JobMeta jobMetaTest = new JobMeta( ); RepositoryDirectoryInterface path = mock( RepositoryDirectoryInterface.class ); when( path.getPath() ).thenReturn( "aPath" ); jobMetaTest.setRepository( mock( Repository.class ) ); jobMetaTest.setRepositoryDirectory( path ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.updateCurrentDir(); assertEquals( "/SomeRepDirectory", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithRepository( ) { JobMeta jobMetaTest = new JobMeta( ); RepositoryDirectoryInterface path = mock( RepositoryDirectoryInterface.class ); when( path.getPath() ).thenReturn( "aPath" ); jobMetaTest.setRepository( mock( Repository.class ) ); jobMetaTest.setRepositoryDirectory( path ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "/SomeRepDirectory", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
Assert.assertEquals( null, jobMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, jobMeta.getVariable( param2 ) ); Assert.assertEquals( childValue3, jobMeta.getVariable( param3 ) ); Assert.assertEquals( parentValue1, jobMeta.getVariable( param1 ) ); Assert.assertEquals( parentValue2, jobMeta.getVariable( param2 ) ); Assert.assertEquals( childValue3, jobMeta.getVariable( param3 ) );
executionConfiguration.getVariables().put( var, jobMeta.getVariable( var ) ); executionConfiguration.getVariables().put( var, jobMeta.getVariable( var ) );
@Test public void testSetInternalEntryCurrentDirectoryWithoutFilenameOrRepository( ) { JobMeta jobMetaTest = new JobMeta( ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "Original value defined at run execution", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testUpdateCurrentDirWithoutFilenameOrRepository( ) { JobMeta jobMetaTest = new JobMeta( ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.updateCurrentDir(); assertEquals( "Original value defined at run execution", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testUpdateCurrentDirWithFilename( ) { JobMeta jobMetaTest = new JobMeta( ); jobMetaTest.setFilename( "hasFilename" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.updateCurrentDir(); assertEquals( "file:///C:/SomeFilenameDirectory", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithFilename( ) { JobMeta jobMetaTest = new JobMeta( ); jobMetaTest.setFilename( "hasFilename" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobMetaTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "file:///C:/SomeFilenameDirectory", jobMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testCurrentDirJob() throws Exception { final String dirName = "dirName"; final String jobName = "job"; JobMeta setupJobMeta = new JobMeta(); setupJobMeta.setName( jobName ); RepositoryDirectoryInterface repoDir = repository.createRepositoryDirectory( new RepositoryDirectory(), dirName ); setupJobMeta.setRepositoryDirectory( repoDir ); repository.save( setupJobMeta, "" ); JobMeta jobMeta = repository.loadJob( jobName, repoDir, null, "" ); assertEquals( repository, jobMeta.getRepository() ); assertEquals( repoDir.getPath(), jobMeta.getRepositoryDirectory().getPath() ); jobMeta.setInternalKettleVariables(); String currentDir = jobMeta.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ); assertEquals( repoDir.getPath(), currentDir ); }