ParameterGeneration extends StepOptimization { @Override public boolean activate( DataServiceExecutor executor, StepInterface stepInterface ) { ParameterGenerationService service = serviceProvider.getService( stepInterface.getStepMeta() ); Condition pushDownCondition = getPushDownCondition( executor.getSql() ); return handlePushDown( service, pushDownCondition, stepInterface ); } 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 testActivation() throws Exception { Condition condition = newCondition( "A_src", "A_value" ); condition.addCondition( newCondition( AND, "B_src", "B_value" ) ); condition.getCondition( 1 ).addCondition( newCondition( OR, "C_src", "C_value" ) ); SQL query = mockSql( condition ); when( executor.getSql() ).thenReturn( query ); assertTrue( paramGen.activate( executor, stepInterface ) ); ArgumentCaptor<Condition> pushDownCaptor = ArgumentCaptor.forClass( Condition.class ); verify( service ).pushDown( pushDownCaptor.capture(), same( paramGen ), same( stepInterface ) ); Condition verify = pushDownCaptor.getValue(); assertEquals( "A_tgt", verify.getCondition( 0 ).getLeftValuename() ); assertEquals( "A_value", verify.getCondition( 0 ).getRightExactString() ); assertEquals( AND, verify.getCondition( 1 ).getOperator() ); assertEquals( "B_tgt", verify.getCondition( 1 ).getCondition( 0 ).getLeftValuename() ); assertEquals( "B_value", verify.getCondition( 1 ).getCondition( 0 ).getRightExactString() ); assertEquals( OR, verify.getCondition( 1 ).getCondition( 1 ).getOperator() ); assertEquals( "C_tgt", verify.getCondition( 1 ).getCondition( 1 ).getLeftValuename() ); assertEquals( "C_value", verify.getCondition( 1 ).getCondition( 1 ).getRightExactString() ); }