@Override BaseStep doCall() { for ( RowSet rowSet : baseStep.getInputRowSets() ) { rowSet.setRowMeta( mock( RowMetaInterface.class ) ); } for ( RowSet rowSet : baseStep.getOutputRowSets() ) { rowSet.setRowMeta( mock( RowMetaInterface.class ) ); } return null; } }
@Override public Object[] getRowFrom( RowSet rowSet ) throws KettleStepException { rowSet.setRowMeta( new RowMeta() ); return new Object[] {}; }
private RowSet mockInputRowSet() { RowSet inputRowSet = smh.getMockInputRowSet( new Object[][] { { "name".getBytes(), "1".getBytes() } } ); inputRowSet.setRowMeta( mockInputRowMeta() ); return inputRowSet; }
/** * Create ExcelWriterStep object and mock some of its required data * * @param fileType * @throws Exception */ private void setupStepMock( String fileType ) throws Exception { step = new ExcelWriterStep( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); step.init( stepMockHelper.initStepMetaInterface, stepMockHelper.initStepDataInterface ); List<Object[]> rows = createRowData(); String[] outFields = new String[] { "col 1", "col 2", "col 3", "col 4" }; RowSet inputRowSet = stepMockHelper.getMockInputRowSet( rows ); RowMetaInterface inputRowMeta = createRowMeta(); inputRowSet.setRowMeta( inputRowMeta ); RowMetaInterface mockOutputRowMeta = mock( RowMetaInterface.class ); when( mockOutputRowMeta.size() ).thenReturn( outFields.length ); when( inputRowSet.getRowMeta() ).thenReturn( inputRowMeta ); step.addRowSetToInputRowSets( inputRowSet ); step.setInputRowMeta( inputRowMeta ); step.addRowSetToOutputRowSets( inputRowSet ); }
@Test public void calculatorShouldClearDataInstance() throws Exception { RowMeta inputRowMeta = new RowMeta(); ValueMetaInteger valueMeta = new ValueMetaInteger( "Value" ); inputRowMeta.addValueMeta( valueMeta ); RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { -1L } ); inputRowSet.setRowMeta( inputRowMeta ); Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ); calculator.addRowSetToInputRowSets( inputRowSet ); calculator.setInputRowMeta( inputRowMeta ); calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface ); CalculatorMeta meta = new CalculatorMeta(); meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test", CalculatorMetaFunction.CALC_ABS, "Value", null, null, ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "" ) } ); CalculatorData data = new CalculatorData(); data = spy( data ); calculator.processRow( meta, data ); verify( data ).getValueMetaFor( eq( valueMeta.getType() ), anyString() ); calculator.processRow( meta, data ); verify( data ).clearValuesMetaMapping(); }
fail(); inputRowSet.setRowMeta( inputRowMeta );
@Test public void testMissingFile() throws KettleException { RowMeta inputRowMeta = new RowMeta(); ValueMetaString pathMeta = new ValueMetaString( "Path" ); inputRowMeta.addValueMeta( pathMeta ); String filepath = "missingFile"; Object[] rows = new Object[] { filepath }; RowSet inputRowSet = smh.getMockInputRowSet( rows ); inputRowSet.setRowMeta( inputRowMeta ); Calculator calculator = spy( new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ) ); calculator.addRowSetToInputRowSets( inputRowSet ); calculator.setInputRowMeta( inputRowMeta ); calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface ); CalculatorMeta meta = new CalculatorMeta(); CalculatorMetaFunction[] calculations = new CalculatorMetaFunction[] { new CalculatorMetaFunction( "result", CalculatorMetaFunction.CALC_MD5, "Path", null, null, ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "" ) }; meta.setCalculation( calculations ); meta.setFailIfNoFile( true ); boolean processed = calculator.processRow( meta, new CalculatorData() ); verify( calculator, times( 1 ) ).logError( argThat( new ArgumentMatcher<String>() { @Override public boolean matches( Object o ) { return ((String) o ).contains( BaseMessages.getString( PKG, "Calculator.Log.NoFile" ) ); } } ) ); assertFalse( processed ); }
inputRowSet.setRowMeta( inputRowMeta ); final String fieldA = inputRowMeta.size() > 0 ? inputRowMeta.getValueMetaList().get( 0 ).getName() : null; final String fieldB = inputRowMeta.size() > 1 ? inputRowMeta.getValueMetaList().get( 1 ).getName() : null;
fail(); inputRowSet.setRowMeta( inputRowMeta );
public void assertRoundStd( final double expectedResult, final double value ) throws KettleException { RowMeta inputRowMeta = new RowMeta(); ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" ); inputRowMeta.addValueMeta( valueMeta ); RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value } ); inputRowSet.setRowMeta( inputRowMeta ); Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ); calculator.addRowSetToInputRowSets( inputRowSet ); calculator.setInputRowMeta( inputRowMeta ); calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface ); CalculatorMeta meta = new CalculatorMeta(); meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test", CalculatorMetaFunction.CALC_ROUND_STD_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "" ) } ); // Verify output try { calculator.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { assertEquals( expectedResult, row[1] ); } } ); calculator.processRow( meta, new CalculatorData() ); } catch ( KettleException ke ) { ke.printStackTrace(); fail(); } }
public void assertRound( final double expectedResult, final double value ) throws KettleException { RowMeta inputRowMeta = new RowMeta(); ValueMetaNumber valueMeta = new ValueMetaNumber( "Value" ); inputRowMeta.addValueMeta( valueMeta ); RowSet inputRowSet = smh.getMockInputRowSet( new Object[] { value } ); inputRowSet.setRowMeta( inputRowMeta ); Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ); calculator.addRowSetToInputRowSets( inputRowSet ); calculator.setInputRowMeta( inputRowMeta ); calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface ); CalculatorMeta meta = new CalculatorMeta(); meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "test", CalculatorMetaFunction.CALC_ROUND_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "" ) } ); // Verify output try { calculator.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { assertEquals( expectedResult, row[1] ); } } ); calculator.processRow( meta, new CalculatorData() ); } catch ( KettleException ke ) { ke.printStackTrace(); fail(); } }
inputRowSet.setRowMeta( inputRowMeta );
inputRowSet.setRowMeta( inputRowMeta );
@Test public void testReturnDigitsOnly() throws KettleException { RowMeta inputRowMeta = new RowMeta(); ValueMetaString nameMeta = new ValueMetaString( "Name" ); inputRowMeta.addValueMeta( nameMeta ); ValueMetaString valueMeta = new ValueMetaString( "Value" ); inputRowMeta.addValueMeta( valueMeta ); RowSet inputRowSet = smh.getMockInputRowSet( new Object[][] { { "name1", "qwe123asd456zxc" }, { "name2", null } } ); inputRowSet.setRowMeta( inputRowMeta ); Calculator calculator = new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ); calculator.addRowSetToInputRowSets( inputRowSet ); calculator.setInputRowMeta( inputRowMeta ); calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface ); CalculatorMeta meta = new CalculatorMeta(); meta.setCalculation( new CalculatorMetaFunction[] { new CalculatorMetaFunction( "digits", CalculatorMetaFunction.CALC_GET_ONLY_DIGITS, "Value", null, null, ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "" ) } ); // Verify output try { calculator.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { assertEquals( "123456", row[ 2 ] ); } } ); calculator.processRow( meta, new CalculatorData() ); } catch ( KettleException ke ) { ke.printStackTrace(); fail(); } }