ParameterGeneration extends StepOptimization { @Override public void init( TransMeta transMeta, DataServiceMeta dataService, PushDownOptimizationMeta optMeta ) { fieldMappings = Lists.newArrayList( Iterables.filter( fieldMappings, SourceTargetFields.IS_DEFINED ) ); StepMeta stepMeta = transMeta.findStep( optMeta.getStepName() ); ParameterGenerationService service = stepMeta != null ? serviceProvider.getService( stepMeta ) : null; String parameterDefault = service != null ? service.getParameterDefault() : ""; String description = String.format( "Auto-generated parameter for Push Down Optimization: %s", optMeta.getStepName() ); try { transMeta.addParameterDefinition( getParameterName(), parameterDefault, description ); transMeta.activateParameters(); } catch ( DuplicateParamException e ) { } } ParameterGeneration( ParameterGenerationFactory serviceProvider ); String getParameterName(); void setParameterName( String parameterName ); List<SourceTargetFields> getFieldMappings(); SourceTargetFields createFieldMapping(); SourceTargetFields createFieldMapping( String source, String target ); SourceTargetFields removeFieldMapping( SourceTargetFields mapping ); @Override void init( TransMeta transMeta, DataServiceMeta dataService, PushDownOptimizationMeta optMeta ); @Override boolean activate( DataServiceExecutor executor, StepInterface stepInterface ); @Override OptimizationImpactInfo preview( DataServiceExecutor executor, StepInterface stepInterface ); @Override String toString(); static final String PUSH_DOWN_FIELD_MAPPINGS; static final String PUSH_DOWN_PARAMETER_NAME; static final String TYPE_NAME; }
@Test public void testInit() throws DuplicateParamException { DataServiceMeta dataService = mock( DataServiceMeta.class ); PushDownOptimizationMeta pdo = new PushDownOptimizationMeta(); pdo.setName( OPT_NAME ); pdo.setStepName( OPT_STEP ); when( transMeta.findStep( OPT_STEP ) ).thenReturn( null, stepMeta ); when( serviceProvider.getService( stepMeta ) ).thenReturn( null, service ); paramGen.init( transMeta, dataService, pdo ); paramGen.init( transMeta, dataService, pdo ); paramGen.init( transMeta, dataService, pdo ); verify( transMeta, times( 2 ) ).addParameterDefinition( eq( PARAM_NAME ), eq( "" ), anyString() ); verify( transMeta ).addParameterDefinition( eq( PARAM_NAME ), eq( EXPECTED_DEFAULT ), anyString() ); doThrow( DuplicateParamException.class ).when( transMeta ).addParameterDefinition( eq( PARAM_NAME ), eq( EXPECTED_DEFAULT ), anyString() ); paramGen.init( transMeta, dataService, pdo ); verify( transMeta, atLeast( 3 ) ).activateParameters(); }