/** * PDI-3064 Test parent transformation overrides parameters for child transformation. * * @throws KettleException */ @Test public void testOverrideMappingParameters() throws KettleException { MappingParameters param = Mockito.mock( MappingParameters.class ); Mockito.when( param.getVariable() ).thenReturn( new String[] { "a", "b" } ); Mockito.when( param.getInputField() ).thenReturn( new String[] { "11", "12" } ); when( transMeta.listParameters() ).thenReturn( new String[] { "a" } ); StepWithMappingMeta .activateParams( trans, trans, step, transMeta.listParameters(), param.getVariable(), param.getInputField() ); // parameters was overridden 2 times // new call of setParameterValue added in StepWithMappingMeta - wantedNumberOfInvocations is now to 2 Mockito.verify( trans, Mockito.times( 2 ) ).setParameterValue( Mockito.anyString(), Mockito.anyString() ); Mockito.verify( trans, Mockito.times( 1 ) ).setVariable( Mockito.anyString(), Mockito.anyString() ); }
/** * Configures the transformation with the given parameters and their values * * @param trans the executable transformation object * @param optionParams the list of parameters to set for the transformation * @param transMeta the transformation metadata * @throws UnknownParamException */ protected static void configureParameters( Trans trans, NamedParams optionParams, TransMeta transMeta ) throws UnknownParamException { trans.initializeVariablesFrom( null ); trans.getTransMeta().setInternalKettleVariables( trans ); // Map the command line named parameters to the actual named parameters. // Skip for the moment any extra command line parameter not known in the transformation. String[] transParams = trans.listParameters(); for ( String param : transParams ) { String value = optionParams.getParameterValue( param ); if ( value != null ) { trans.setParameterValue( param, value ); transMeta.setParameterValue( param, value ); } } // Put the parameters over the already defined variable space. Parameters get priority. trans.activateParameters(); }
private void passParametersToTrans( Trans internalTrans, RowMetaAndData rowMetaAndData ) throws KettleException { internalTrans.clearParameters(); String[] parameterNames = internalTrans.listParameters(); for ( int i = 0; i < this.parameters.getVariable().length; ++i ) { String variable = this.parameters.getVariable()[ i ]; String fieldName = this.parameters.getField()[ i ]; String inputValue = this.parameters.getInput()[ i ]; String value; if ( !Utils.isEmpty( fieldName ) ) { int idx = rowMetaAndData.getRowMeta().indexOfValue( fieldName ); if ( idx < 0 ) { throw new KettleException( BaseMessages.getString( PKG, "TransExecutor.Exception.UnableToFindField", fieldName ) ); } value = rowMetaAndData.getString( idx, "" ); } else { value = this.parentTrans.environmentSubstitute( inputValue ); } if ( Const.indexOfString( variable, parameterNames ) < 0 ) { internalTrans.setVariable( variable, Const.NVL( value, "" ) ); } else { internalTrans.setParameterValue( variable, Const.NVL( value, "" ) ); } } internalTrans.activateParameters(); }
String value = runTimeParameters.getVariable( param ); if ( value != null ) { trans.setParameterValue( param, value ); transMeta.setParameterValue( param, value );