Java Code Examples for org.pentaho.di.trans.TransMeta#findTransHop()

The following examples show how to use org.pentaho.di.trans.TransMeta#findTransHop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobEntryTransIntIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private String createPDI14676Transformation() throws IOException, KettleException {
  // Setup Transformation
  String rowGenStepName = "Generate Rows";
  RowGeneratorMeta rowGenMeta = new RowGeneratorMeta();
  rowGenMeta.setRowLimit( String.valueOf( Integer.MAX_VALUE ) );
  rowGenMeta.setNeverEnding( true );
  rowGenMeta.setIntervalInMs( "0" );
  rowGenMeta.allocate( 0 );

  TransMeta tMeta = TransTestFactory.generateTestTransformation( new Variables(), rowGenMeta, rowGenStepName );
  
  // Remove the Injector step, as it's not needed for this transformation
  TransHopMeta hopToRemove = tMeta.findTransHop( tMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ), tMeta.findStep( rowGenStepName ) );
  tMeta.removeTransHop( tMeta.indexOfTransHop( hopToRemove ) );
  tMeta.removeStep( tMeta.indexOfStep( tMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ) ) );

  // Write transformation to temp file, for use within a job
  String transFilename = TestUtilities.createEmptyTempFile( this.getClass().getSimpleName() + "_PDI14676_", ".ktr" );
  FileObject transFile = TestUtils.getFileObject( transFilename );
  OutputStream outStream = transFile.getContent().getOutputStream();
  PrintWriter pw = new PrintWriter( outStream );
  pw.write( tMeta.getXML() );
  pw.close();
  outStream.close();
  return transFilename;
}
 
Example 2
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderName() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ ".*" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 2, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedFilename, result.get( 0 ).getString( "short_filename", "failure" ) );
  assertTrue( result.get( 1 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedSubFolderName, result.get( 1 ).getString( "short_filename", "failure" ) );
}
 
Example 3
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderNameWithoutWildcard() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ "" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 2, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedFilename, result.get( 0 ).getString( "short_filename", "failure" ) );
  assertTrue( result.get( 1 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedSubFolderName, result.get( 1 ).getString( "short_filename", "failure" ) );
}
 
Example 4
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderNameOnlyFiles() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ ".*" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );
  meta.setFilterFileType( 1 );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 1, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedFilename, result.get( 0 ).getString( "short_filename", "failure" ) );
}
 
Example 5
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderNameWithoutWildcardAndOnlyFiles() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ "" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );
  meta.setFilterFileType( 1 );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 1, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedFilename, result.get( 0 ).getString( "short_filename", "failure" ) );
}
 
Example 6
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderNameOnlyFolders() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ ".*" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );
  meta.setFilterFileType( 2 );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 1, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedSubFolderName, result.get( 0 ).getString( "short_filename", "failure" ) );
}
 
Example 7
Source File: GetFileNamesIntIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterFolderNameWithoutWildcardAndOnlyFolders() throws KettleException, IOException {
  GetFileNamesMeta meta = new GetFileNamesMeta();
  meta.setDefault();

  meta.allocate( 1 );
  meta.setFileName( new String[]{ "${MY_FOLDER_PARAM}" } );
  meta.setFileMask( new String[]{ "" } );
  meta.setExcludeFileMask( new String[]{ "" } );
  meta.setFileRequired( new String[]{ "Y" } );
  meta.setIncludeSubFolders( new String[]{ "N" } );
  meta.setFilterFileType( 2 );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, STEPNAME );
  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( STEPNAME ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  transMeta.addParameterDefinition( "MY_FOLDER_PARAM", "C:\\ThisFolderDoesNotExist", "The folder to look in for files" );
  Variables varSpace = new Variables();
  varSpace.setVariable( "MY_FOLDER_PARAM", tempFolder.getRoot().getAbsolutePath() );

  // Content inside selected folder
  String expectedFilename = "file.tmp";
  String expectedSubFolderName = "subfolder";
  tempFolder.newFile( expectedFilename );
  tempFolder.newFolder( expectedSubFolderName );

  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, STEPNAME,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>(), null, varSpace );

  // Check that the expected file was located correctly
  assertNotNull( result );
  assertEquals( 1, result.size() );
  assertTrue( result.get( 0 ).getRowMeta().indexOfValue( "short_filename" ) >= 0 );
  assertEquals( expectedSubFolderName, result.get( 0 ).getString( "short_filename", "failure" ) );
}
 
Example 8
Source File: AccessOutputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void checkResult( String fileName, String tableName, List<RowMetaAndData> expected ) throws KettleException, IOException {
  assertNotNull( fileName );
  assertNotNull( tableName );
  assertTrue( expected.size() > 0 );

  final String stepName = "My Access Input Step";
  AccessInputMeta stepMeta = new AccessInputMeta();
  stepMeta.allocateFiles( 1 );
  stepMeta.setFileName( new String[] { fileName } );
  stepMeta.setTableName( tableName );
  stepMeta.allocateFields( 1 );
  stepMeta.setInputFields( getInputFields( expected ) );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, stepMeta, stepName );

  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  List<RowMetaAndData> ret =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>() );

  assertEquals( "Expected and actual row size should match", expected.size(), ret.size() );
  for ( int i = 0; i < expected.size(); i++ ) {
    assertEquals( "Checking Row #" + i, expected.get( i ), ret.get( i ) );
  }
}
 
Example 9
Source File: ExcelWriterStepIntIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testPDI11374() throws KettleException, IOException {
  String stepName = "Excel Writer";
  ExcelWriterStepMeta meta = new ExcelWriterStepMeta();
  meta.setDefault();

  File tempOutputFile = File.createTempFile( "testPDI11374", ".xlsx" );
  tempOutputFile.deleteOnExit();
  meta.setFileName( tempOutputFile.getAbsolutePath().replace( ".xlsx", "" ) );
  meta.setExtension( "xlsx" );
  meta.setSheetname( "Sheet10" );
  meta.setOutputFields( new ExcelWriterStepField[] {} );
  meta.setHeaderEnabled( true );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, stepName );
  List<RowMetaAndData> inputList = getPDI11374RowMetaAndData();
  TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
    TransTestFactory.DUMMY_STEPNAME, inputList );

  try {
    Thread.sleep( 1000 );
  } catch ( InterruptedException ignore ) {
    // Wait a second to ensure that the output file is properly closed
  }

  // Now, check the result
  String checkStepName = "Excel Input";
  ExcelInputMeta excelInput = new ExcelInputMeta();
  excelInput.setFileName( new String[] { tempOutputFile.getAbsolutePath() } );
  excelInput.setFileMask( new String[] { "" } );
  excelInput.setExcludeFileMask( new String[] { "" } );
  excelInput.setFileRequired( new String[] { "N" } );
  excelInput.setIncludeSubFolders( new String[]{ "N" } );
  excelInput.setSpreadSheetType( SpreadSheetType.POI );
  excelInput.setSheetName( new String[] { "Sheet10" } );
  excelInput.setStartColumn( new int[] { 0 } );
  excelInput.setStartRow( new int[] { 0 } );
  excelInput.setStartsWithHeader( false ); // Ensures that we can check the header names

  ExcelInputField[] fields = new ExcelInputField[5];
  for ( int i = 0; i < 5; i++ ) {
    fields[i] = new ExcelInputField();
    fields[i].setName( "field" + ( i + 1 ) );
  }
  excelInput.setField( fields );

  transMeta = TransTestFactory.generateTestTransformation( null, excelInput, checkStepName );

  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  inputList = new ArrayList<RowMetaAndData>();
  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, inputList );

  assertNotNull( result );
  assertEquals( 2, result.size() );
  assertEquals( 5, result.get( 0 ).getRowMeta().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 0 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 1 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 2 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 3 ).getType() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 4 ).getType() );

  assertEquals( "col1", result.get( 0 ).getString( 0, "default-value" ) );
  assertEquals( "col2", result.get( 0 ).getString( 1, "default-value" ) );
  assertEquals( "col3", result.get( 0 ).getString( 2, "default-value" ) );
  assertEquals( "col4", result.get( 0 ).getString( 3, "default-value" ) );
  assertEquals( "col5", result.get( 0 ).getString( 4, "default-value" ) );

  assertEquals( "data1", result.get( 1 ).getString( 0, "default-value" ) );
  assertEquals( "data2", result.get( 1 ).getString( 1, "default-value" ) );
  assertEquals( "data3", result.get( 1 ).getString( 2, "default-value" ) );
  assertEquals( "data4", result.get( 1 ).getString( 3, "default-value" ) );
  assertEquals( "data5", result.get( 1 ).getString( 4, "default-value" ) );
}
 
Example 10
Source File: CubeInputStepIntIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testPDI12897() throws KettleException, IOException {
  File tempOutputFile = File.createTempFile( "testPDI11374", ".cube" );
  tempOutputFile.deleteOnExit();

  String stepName = "Cube Output";
  CubeOutputMeta meta = new CubeOutputMeta();
  meta.setDefault();
  meta.setFilename( tempOutputFile.getAbsolutePath() );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, stepName );
  List<RowMetaAndData> inputList = getSampleData();
  TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
    TransTestFactory.DUMMY_STEPNAME, inputList );

  try {
    Thread.sleep( 1000 );
  } catch ( InterruptedException ignored ) {
    // Continue
  }

  // Now, check the result
  Variables varSpace = new Variables();
  varSpace.setVariable( "ROWS", "2" );

  String checkStepName = "Cube Input";
  CubeInputMeta inputMeta = new CubeInputMeta();
  inputMeta.setFilename( tempOutputFile.getAbsolutePath() );
  inputMeta.setRowLimit( "${ROWS}" );

  transMeta = TransTestFactory.generateTestTransformation( varSpace, inputMeta, checkStepName );

  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  inputList = new ArrayList<RowMetaAndData>();
  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, inputList );

  assertNotNull( result );
  assertEquals( 2, result.size() );
  assertEquals( 1, result.get( 0 ).getRowMeta().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 0 ).getType() );
  assertEquals( "col1", result.get( 0 ).getValueMeta( 0 ).getName() );
  assertEquals( "data1", result.get( 0 ).getString( 0, "fail" ) );
  assertEquals( "data2", result.get( 1 ).getString( 0, "fail" ) );
}
 
Example 11
Source File: CubeInputStepIntIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoLimit() throws KettleException, IOException {
  File tempOutputFile = File.createTempFile( "testNoLimit", ".cube" );
  tempOutputFile.deleteOnExit();

  String stepName = "Cube Output";
  CubeOutputMeta meta = new CubeOutputMeta();
  meta.setDefault();
  meta.setFilename( tempOutputFile.getAbsolutePath() );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, stepName );
  List<RowMetaAndData> inputList = getSampleData();
  TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
    TransTestFactory.DUMMY_STEPNAME, inputList );

  try {
    Thread.sleep( 1000 );
  } catch ( InterruptedException ignored ) {
    // Continue
  }

  // Now, check the result
  String checkStepName = "Cube Input";
  CubeInputMeta inputMeta = new CubeInputMeta();
  inputMeta.setFilename( tempOutputFile.getAbsolutePath() );

  transMeta = TransTestFactory.generateTestTransformation( null, inputMeta, checkStepName );

  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  inputList = new ArrayList<RowMetaAndData>();
  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, inputList );

  assertNotNull( result );
  assertEquals( 5, result.size() );
  assertEquals( 1, result.get( 0 ).getRowMeta().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 0 ).getType() );
  assertEquals( "col1", result.get( 0 ).getValueMeta( 0 ).getName() );
  assertEquals( "data1", result.get( 0 ).getString( 0, "fail" ) );
  assertEquals( "data2", result.get( 1 ).getString( 0, "fail" ) );
  assertEquals( "data3", result.get( 2 ).getString( 0, "fail" ) );
  assertEquals( "data4", result.get( 3 ).getString( 0, "fail" ) );
  assertEquals( "data5", result.get( 4 ).getString( 0, "fail" ) );
}
 
Example 12
Source File: CubeInputStepIntIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testNumericLimit() throws KettleException, IOException {
  File tempOutputFile = File.createTempFile( "testNumericLimit", ".cube" );
  tempOutputFile.deleteOnExit();

  String stepName = "Cube Output";
  CubeOutputMeta meta = new CubeOutputMeta();
  meta.setDefault();
  meta.setFilename( tempOutputFile.getAbsolutePath() );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( null, meta, stepName );
  List<RowMetaAndData> inputList = getSampleData();
  TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
    TransTestFactory.DUMMY_STEPNAME, inputList );

  try {
    Thread.sleep( 1000 );
  } catch ( InterruptedException ignored ) {
    // Continue
  }

  // Now, check the result
  String checkStepName = "Cube Input";
  CubeInputMeta inputMeta = new CubeInputMeta();
  inputMeta.setFilename( tempOutputFile.getAbsolutePath() );
  inputMeta.setRowLimit( "3" );

  transMeta = TransTestFactory.generateTestTransformation( null, inputMeta, checkStepName );

  //Remove the Injector hop, as it's not needed for this transformation
  TransHopMeta injectHop = transMeta.findTransHop( transMeta.findStep( TransTestFactory.INJECTOR_STEPNAME ),
    transMeta.findStep( stepName ) );
  transMeta.removeTransHop( transMeta.indexOfTransHop( injectHop ) );

  inputList = new ArrayList<RowMetaAndData>();
  List<RowMetaAndData> result =
    TransTestFactory.executeTestTransformation( transMeta, TransTestFactory.INJECTOR_STEPNAME, stepName,
      TransTestFactory.DUMMY_STEPNAME, inputList );

  assertNotNull( result );
  assertEquals( 3, result.size() );
  assertEquals( 1, result.get( 0 ).getRowMeta().size() );
  assertEquals( ValueMetaInterface.TYPE_STRING, result.get( 0 ).getValueMeta( 0 ).getType() );
  assertEquals( "col1", result.get( 0 ).getValueMeta( 0 ).getName() );
  assertEquals( "data1", result.get( 0 ).getString( 0, "fail" ) );
  assertEquals( "data2", result.get( 1 ).getString( 0, "fail" ) );
  assertEquals( "data3", result.get( 2 ).getString( 0, "fail" ) );
}