org.pentaho.di.core.variables.Variables Java Examples

The following examples show how to use org.pentaho.di.core.variables.Variables. 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: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void infoStepFieldsAreNotIncludedInGetStepFields() throws KettleStepException {
  // validates that the fields from info steps are not included in the resulting step fields for a stepMeta.
  //  This is important with steps like StreamLookup and Append, where the previous steps may or may not
  //  have their fields included in the current step.

  TransMeta transMeta = new TransMeta( new Variables() );
  StepMeta toBeAppended1 = testStep( "toBeAppended1",
    emptyList(),  // no info steps
    asList( "field1", "field2" )  // names of fields from this step
  );
  StepMeta toBeAppended2 = testStep( "toBeAppended2", emptyList(), asList( "field1", "field2" ) );

  StepMeta append = testStep( "append",
    asList( "toBeAppended1", "toBeAppended2" ),  // info step names
    singletonList( "outputField" )   // output field of this step
  );
  StepMeta after = new StepMeta( "after", new DummyTransMeta() );

  wireUpTestTransMeta( transMeta, toBeAppended1, toBeAppended2, append, after );

  RowMetaInterface results = transMeta.getStepFields( append, after, mock( ProgressMonitorListener.class ) );

  assertThat( 1, equalTo( results.size() ) );
  assertThat( "outputField", equalTo( results.getFieldNames()[ 0 ] ) );
}
 
Example #2
Source File: MonetDBBulkLoaderIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoInput() {
  String oneStepname = "Monet Bulk Loader";
  MonetDBBulkLoaderMeta meta = new MonetDBBulkLoaderMeta();
  DatabaseMeta database = new DatabaseMeta();
  database.setDatabaseInterface( new MonetDBDatabaseMeta() );
  meta.setDefault();
  meta.setDatabaseMeta( database );
  TransMeta transMeta = TransTestFactory.generateTestTransformation( new Variables(), meta, oneStepname );

  try {
    TransTestFactory.executeTestTransformation( transMeta, oneStepname, new ArrayList<RowMetaAndData>() );
  } catch ( KettleException e ) {
    // The Monet DB Bulk Loader step should finish quietly if no input rows
    fail();
  }
}
 
Example #3
Source File: MongoDbOutputTest.java    From pentaho-mongodb-plugin with Apache License 2.0 6 votes vote down vote up
@Test public void testTopLevelObjectStructureNoNestedDocs() throws Exception {
  List<MongoDbOutputMeta.MongoField> paths = asList( mf( "field1", true, "" ), mf( "field2", true, "" ) );

  RowMetaInterface rmi = new RowMeta();
  rmi.addValueMeta( new ValueMetaString( "field1" ) );
  rmi.addValueMeta( new ValueMetaInteger( "field2" ) );

  Object[] row = new Object[ 2 ];
  row[ 0 ] = "value1";
  row[ 1 ] = 12L;
  VariableSpace vs = new Variables();

  for ( MongoDbOutputMeta.MongoField f : paths ) {
    f.init( vs );
  }

  DBObject result = kettleRowToMongo( paths, rmi, row, MongoDbOutputData.MongoTopLevel.RECORD, false );

  assertEquals( JSON.serialize( result ), "{ \"field1\" : \"value1\" , \"field2\" : 12}" );
}
 
Example #4
Source File: JobGenerator.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private TransMeta generateDateTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
  // We actually load the transformation from a template and then slightly modify it.
  //
  String filename = "/org/pentaho/di/resources/Generate date dimension.ktr";
  InputStream inputStream = getClass().getResourceAsStream(filename);
  TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);

  // Find the table output step and inject the target table name and database...
  //
  StepMeta stepMeta = transMeta.findStep("TARGET");
  if (stepMeta!=null) {
    TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(databaseMeta);
    String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
    meta.setTableName(phTable);
  }

  return transMeta;
}
 
Example #5
Source File: SharedObjects.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static final String createFilename( String sharedObjectsFile ) {
  String filename;
  if ( Utils.isEmpty( sharedObjectsFile ) ) {
    // First fallback is the environment/kettle variable ${KETTLE_SHARED_OBJECTS}
    // This points to the file
    filename = Variables.getADefaultVariableSpace().getVariable( Const.KETTLE_SHARED_OBJECTS );

    // Last line of defence...
    if ( Utils.isEmpty( filename ) ) {
      filename = Const.getSharedObjectsFile();
    }
  } else {
    filename = sharedObjectsFile;
  }
  return filename;
}
 
Example #6
Source File: TextFileInputIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testPDI18818() throws KettleException {
  KettleEnvironment.init();
  String path = getClass().getResource( "text-file-input-pdi-18818.ktr" ).getPath();
  Variables variables = new Variables();
  variables.setVariable( "testfolder", getClass().getResource( "" ).getPath() );
  TransMeta transMeta = new TransMeta( path, variables );
  Trans trans = new Trans( transMeta );
  trans.prepareExecution( null );
  trans.startThreads();
  trans.waitUntilFinished();

  //Did we read both values?
  assertEquals( 1, trans.getSteps().get( 0 ).step.getLinesWritten() );

  //Did we read both files?
  assertEquals( 6, trans.getSteps().get( 1 ).step.getLinesWritten() );

  //Did we find any nulls?
  assertEquals( 0, trans.getSteps().get( 4 ).step.getLinesRead() );
}
 
Example #7
Source File: TextFileInputIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDataFromListOfFilesFromPreviousStep() throws KettleException {
  KettleEnvironment.init();
  String path = getClass().getResource( "text-file-input-get-data-from-files-from-previous-step.ktr" ).getPath();
  Variables variables = new Variables();
  variables.setVariable( "testfolder", getClass().getResource( "" ).getPath() );
  TransMeta transMeta = new TransMeta( path, variables );
  Trans trans = new Trans( transMeta );
  trans.prepareExecution( null );
  trans.startThreads();
  trans.waitUntilFinished();
  assertEquals( 14, trans.getSteps().get( 1 ).step.getLinesWritten() );
  assertEquals( 21, trans.getSteps().get( 1 ).step.getLinesInput() );
  // The path contains 7 entries containing csv file paths
  assertEquals( 7, trans.getSteps().get( 0 ).step.getLinesWritten() );
}
 
Example #8
Source File: AbstractMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializeShareInjectVariables() {
  meta.initializeVariablesFrom( null );
  VariableSpace parent = mock( VariableSpace.class );
  when( parent.getVariable( "var1" ) ).thenReturn( "x" );
  when( parent.listVariables() ).thenReturn( new String[]{ "var1" } );
  meta.initializeVariablesFrom( parent );
  assertEquals( "x", meta.getVariable( "var1" ) );
  assertNotNull( meta.listVariables() );
  VariableSpace newVars = mock( VariableSpace.class );
  when( newVars.getVariable( "var2" ) ).thenReturn( "y" );
  when( newVars.listVariables() ).thenReturn( new String[]{ "var2" } );
  meta.shareVariablesWith( newVars );
  assertEquals( "y", meta.getVariable( "var2" ) );
  Map<String, String> props = new HashMap<>();
  props.put( "var3", "a" );
  props.put( "var4", "b" );
  meta.shareVariablesWith( new Variables() );
  meta.injectVariables( props );
  // Need to "Activate" the injection, we can initialize from null
  meta.initializeVariablesFrom( null );
  assertEquals( "a", meta.getVariable( "var3" ) );
  assertEquals( "b", meta.getVariable( "var4" ) );
}
 
Example #9
Source File: TransSupplier.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the appropriate trans.  Either 1)  A {@link TransWebSocketEngineAdapter} wrapping an Engine if an alternate
 * execution engine has been selected 2)  A legacy {@link Trans} otherwise.
 */
public Trans get() {
  if ( Utils.isEmpty( transMeta.getVariable( "engine" ) ) ) {
    log.logBasic( BaseMessages.getString( PKG, MSG_KETTLE_ENGINE ) );
    return fallbackSupplier.get();
  }

  Variables variables = new Variables();
  variables.initializeVariablesFrom( null );
  String protocol = transMeta.environmentSubstitute( transMeta.getVariable( "engine.scheme" ) );
  String url = transMeta.environmentSubstitute( transMeta.getVariable( "engine.url" ) );

  URI uri = URI.create( protocol + url );

  //default value for ssl for now false
  boolean ssl = "https".equalsIgnoreCase( protocol ) || "wss".equalsIgnoreCase( protocol );
  log.logBasic( BaseMessages.getString( PKG, MSG_SPARK_ENGINE, protocol, url ) );
  return new TransWebSocketEngineAdapter( transMeta, uri.getHost(), uri.getPort(), ssl );
}
 
Example #10
Source File: VFSFileProvider.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * @param file
 * @param newPath
 * @param overwrite
 * @return
 */
private VFSFile doMove( VFSFile file, String newPath, boolean overwrite ) {
  try {
    FileObject fileObject = KettleVFS
      .getFileObject( file.getPath(), new Variables(), VFSHelper.getOpts( file.getPath(), file.getConnection() ) );
    FileObject renameObject = KettleVFS
      .getFileObject( newPath, new Variables(), VFSHelper.getOpts( file.getPath(), file.getConnection() ) );
    if ( overwrite && renameObject.exists() ) {
      renameObject.delete();
    }
    fileObject.moveTo( renameObject );
    if ( file instanceof VFSDirectory ) {
      return VFSDirectory.create( renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(),
        file.getDomain() );
    } else {
      return VFSFile.create( renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(),
        file.getDomain() );
    }
  } catch ( KettleFileException | FileSystemException e ) {
    return null;
  }
}
 
Example #11
Source File: SubtransExecutorTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void stopsAll() throws KettleException {
  TransMeta parentMeta =
    new TransMeta( this.getClass().getResource( "subtrans-executor-parent.ktr" ).getPath(), new Variables() );
  TransMeta subMeta =
    new TransMeta( this.getClass().getResource( "subtrans-executor-sub.ktr" ).getPath(), new Variables() );
  LoggingObjectInterface loggingObject = new LoggingObject( "anything" );
  Trans parentTrans = new Trans( parentMeta, loggingObject );
  SubtransExecutor subtransExecutor =
    new SubtransExecutor( "subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "", 1001 );
  subtransExecutor.running = Mockito.spy( subtransExecutor.running );
  RowMetaInterface rowMeta = parentMeta.getStepFields( "Data Grid" );
  List<RowMetaAndData> rows = Arrays.asList(
    new RowMetaAndData( rowMeta, "Pentaho", 1L ),
    new RowMetaAndData( rowMeta, "Pentaho", 2L ),
    new RowMetaAndData( rowMeta, "Pentaho", 3L ),
    new RowMetaAndData( rowMeta, "Pentaho", 4L ) );
  subtransExecutor.execute( rows );
  verify( subtransExecutor.running ).add( any() );
  subtransExecutor.stop();
  assertTrue( subtransExecutor.running.isEmpty() );
}
 
Example #12
Source File: GetVariableMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetValueMetaPlugin() throws KettleStepException {
  GetVariableMeta meta = new GetVariableMeta();
  meta.setDefault();

  FieldDefinition field = new FieldDefinition();
  field.setFieldName( "outputField" );
  field.setVariableString( String.valueOf( 2000000L ) );
  field.setFieldType( ValueMetaInterface.TYPE_TIMESTAMP );
  meta.setFieldDefinitions( new FieldDefinition[]{ field } );

  RowMetaInterface rowMeta = new RowMeta();
  meta.getFields( rowMeta, "stepName", null, null, new Variables(), null, null );

  assertNotNull( rowMeta );
  assertEquals( 1, rowMeta.size() );
  assertEquals( "outputField", rowMeta.getFieldNames()[0] );
  assertEquals( ValueMetaInterface.TYPE_TIMESTAMP, rowMeta.getValueMeta( 0 ).getType() );
  assertTrue( rowMeta.getValueMeta( 0 ) instanceof ValueMetaTimestamp );
}
 
Example #13
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
protected void viewData() {
  try {
    DataSet set = new DataSet();
    getInfo( set );
    verifySettings();

    List<Object[]> setRows = set.getAllRows( LogChannel.UI );
    RowMetaInterface setRowMeta = set.getSetRowMeta( false );

    PreviewRowsDialog previewRowsDialog = new PreviewRowsDialog( shell, new Variables(), SWT.NONE, set.getName(), setRowMeta, setRows );
    previewRowsDialog.open();

  } catch ( Exception e ) {
    new ErrorDialog( shell, "Error", "Error previewing data from dataset table", e );
  }
}
 
Example #14
Source File: DataSetCsvGroup.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
/**
 * Get the base folder for the data set group
 *
 * @param group
 * @return
 */
private static String getDataSetFolder( DataSetGroup group ) {
  String folderName = group.getFolderName();
  if ( StringUtils.isEmpty( folderName ) ) {
    folderName = System.getProperty( VARIABLE_DATASETS_BASE_PATH );
  }
  if ( StringUtils.isEmpty( folderName ) ) {
    // Local folder
    folderName = ".";
  } else {
    // Let's not forget to replace variables as well...
    //
    VariableSpace space = Variables.getADefaultVariableSpace();
    folderName = space.environmentSubstitute( folderName );
  }

  if ( !folderName.endsWith( File.separator ) ) {
    folderName += File.separator;
  }

  return folderName;
}
 
Example #15
Source File: JsonInputIntTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoInput() throws KettleException {
  String stepName = "noInputStep";
  JsonInputMeta meta = new JsonInputMeta();
  meta.setInFields( true );
  meta.setFieldValue( "myJSONStringField" );
  JsonInputField field = new JsonInputField( "test" );
  field.setPath( "$.value" );
  meta.setInputFields( new JsonInputField[]{ field } );

  TransMeta transMeta = TransTestFactory.generateTestTransformation( new Variables(), meta, stepName );
  List<RowMetaAndData> result = TransTestFactory.executeTestTransformation( transMeta,
    TransTestFactory.INJECTOR_STEPNAME, stepName, TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>() );

  assertNotNull( result );
  assertTrue( result.isEmpty() );
}
 
Example #16
Source File: VFSFileProvider.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @param folder
 * @return
 */
@Override public VFSFile add( VFSFile folder ) {
  try {
    FileObject fileObject = KettleVFS
      .getFileObject( folder.getPath(), new Variables(),
        VFSHelper.getOpts( folder.getPath(), folder.getConnection() ) );
    fileObject.createFolder();
    String parent = folder.getPath().substring( 0, folder.getPath().length() - 1 );
    return VFSDirectory.create( parent, fileObject, folder.getConnection(), folder.getDomain() );
  } catch ( KettleFileException | FileSystemException ignored ) {
    // Ignored
  }
  return null;
}
 
Example #17
Source File: RestMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testStepChecks() {
  RestMeta meta = new RestMeta();
  List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
  TransMeta transMeta = new TransMeta();
  StepMeta step = new StepMeta();
  RowMetaInterface prev = new RowMeta();
  RowMetaInterface info = new RowMeta();
  String[] input = new String[0];
  String[] output = new String[0];
  VariableSpace variables = new Variables();
  Repository repo = null;
  IMetaStore metaStore = null;

  // In a default configuration, it's expected that some errors will occur.
  // For this, we'll grab a baseline count of the number of errors
  // as the error count should decrease as we change configuration settings to proper values.
  remarks.clear();
  meta.check( remarks, transMeta, step, prev, input, output, info, variables, repo, metaStore );
  final int errorsDefault = getCheckResultErrorCount( remarks );
  assertTrue( errorsDefault > 0 );

  // Setting the step to read the URL from a field should fix one of the check() errors
  meta.setUrlInField( true );
  meta.setUrlField( "urlField" );
  prev.addValueMeta( new ValueMetaString( "urlField" ) );
  remarks.clear();
  meta.check( remarks, transMeta, step, prev, input, output, info, variables, repo, metaStore );
  int errorsCurrent = getCheckResultErrorCount( remarks );
  assertTrue( errorsDefault > errorsCurrent );
}
 
Example #18
Source File: TransExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getUsedVariables( TransMeta transMeta ) {
  Properties sp = new Properties();
  VariableSpace space = Variables.getADefaultVariableSpace();

  String[] keys = space.listVariables();
  for ( int i = 0; i < keys.length; i++ ) {
    sp.put( keys[i], space.getVariable( keys[i] ) );
  }

  List<String> vars = transMeta.getUsedVariables();
  if ( vars != null && vars.size() > 0 ) {
    HashMap<String, String> newVariables = new HashMap<String, String>();

    for ( int i = 0; i < vars.size(); i++ ) {
      String varname = vars.get( i );
      if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) {
        newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
      }
    }
    // variables.clear();
    variables.putAll( newVariables );
  }

  // Also add the internal job variables if these are set...
  //
  for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
    String value = transMeta.getVariable( variableName );
    if ( !Utils.isEmpty( value ) ) {
      variables.put( variableName, value );
    }
  }
}
 
Example #19
Source File: CurrentDirectoryResolver.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * The logic of this method:
 * 
 * if we have directory we return the child var space with directory used as system property
 * if we have not directory we return the child var space with directory extracted from filanme
 * if we don not have directory and filename we will return the child var space without updates
 * 
 * 
 * @param parentVariables - parent variable space which can be inherited
 * @param directory - current path which will be used as path for start trans/job
 * @param filename - is file which we use at this moment
 * @param inheritParentVar - flag which indicate should we inherit variables from parent var space to child var space
 * @return new var space if inherit was set false or child var space with updated system variables
 */
public VariableSpace resolveCurrentDirectory( VariableSpace parentVariables, RepositoryDirectoryInterface directory, String filename ) {
  Variables tmpSpace = new Variables();
  tmpSpace.setParentVariableSpace( parentVariables );
  tmpSpace.initializeVariablesFrom( parentVariables );

  if ( directory != null ) {
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, directory.toString() );
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, directory.toString() );
    tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, directory.toString() );
  } else if ( filename != null ) {
    try {
      FileObject fileObject = KettleVFS.getFileObject( filename, tmpSpace );

      if ( !fileObject.exists() ) {
        // don't set variables if the file doesn't exist
        return tmpSpace;
      }

      FileName fileName = fileObject.getName();

      // The filename of the transformation
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName() );

      // The directory of the transformation
      FileName fileDir = fileName.getParent();
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, fileDir.getURI() );
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI() );
      tmpSpace.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, fileDir.getURI() );
    } catch ( Exception e ) {
    }
  }
  return tmpSpace;
}
 
Example #20
Source File: BaseStreamStepMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckErrorsOnSubStepName() {
  List<CheckResultInterface> remarks = new ArrayList<>();
  Variables space = new Variables();

  meta.setBatchSize( "10" );
  meta.setBatchDuration( "10" );
  meta.setSubStep( "MissingStep" );
  meta.check( remarks, null, null, null, null, null, null, space, null, null );
  assertEquals( 1, remarks.size() );
  assertEquals( "Unable to complete \"null\".  Cannot return fields from \"MissingStep\" because it does not exist in the sub-transformation.", remarks.get( 0 ).getText() );
}
 
Example #21
Source File: MailTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void processAttachedFilesNotDynamicTest() throws KettleException {
  Mail step =
    spy( new Mail( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta,
      stepMockHelper.trans ) );
  step.init( stepMockHelper.initStepMetaInterface, stepMockHelper.initStepDataInterface );
  step.setParentVariableSpace( new Variables() );

  RowMetaInterface rowMetaMock = mock( RowMetaInterface.class );

  when( ( (MailMeta) stepMockHelper.initStepMetaInterface ).isDynamicFilename() ).thenReturn( true );
  Whitebox.setInternalState( stepMockHelper.initStepDataInterface, "indexOfSourceFilename", 0 );
  Whitebox.setInternalState( stepMockHelper.initStepDataInterface, "previousRowMeta", rowMetaMock );
  when( rowMetaMock.indexOfValue( "dynamicWildcard" ) ).thenReturn( 0 );

  when( ( (MailMeta) stepMockHelper.initStepMetaInterface ).isDynamicFilename() ).thenReturn( false );
  when( ( (MailMeta) stepMockHelper.initStepMetaInterface ).getSourceFileFoldername() ).thenReturn( "sourceFileFolderName" );
  when( ( (MailMeta) stepMockHelper.initStepMetaInterface ).getSourceWildcard() ).thenReturn( "sourceWildcard" );
  when( step.environmentSubstitute( "sourceFileFolderName" ) ).thenReturn( "sourceFileFolderName" );
  when( step.environmentSubstitute( "sourceWildcard" ) ).thenReturn( "sourceWildcard" );

  step.processAttachedFiles();

  assertEquals( 0, stepMockHelper.initStepDataInterface.indexOfSourceWildcard );
  assertEquals( "sourceFileFolderName", stepMockHelper.initStepDataInterface.realSourceFileFoldername );
  assertEquals( "sourceWildcard", stepMockHelper.initStepDataInterface.realSourceWildcard );
}
 
Example #22
Source File: JsonInputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testJsonInputMetaInputFieldsNotOverwritten() throws Exception {
  JsonInputField inputField = new JsonInputField();
  final String PATH = "$..book[?(@.category=='${category}')].price";
  inputField.setPath( PATH );
  inputField.setType( ValueMetaInterface.TYPE_STRING );
  final JsonInputMeta inputMeta = createSimpleMeta( "json", inputField );
  VariableSpace variables = new Variables();
  variables.setVariable( "category", "fiction" );
  JsonInput jsonInput = createJsonInput( "json", inputMeta, variables, new Object[] { getBasicTestJson() } );
  processRows( jsonInput, 2 );
  assertEquals( "Meta input fields paths should be the same after processRows", PATH, inputMeta.getInputFields()[0].getPath() );
}
 
Example #23
Source File: PDI7502IT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private TransMeta generateSampleTrans( ProcessorType type ) {
  PentahoReportingOutputMeta proMeta = new PentahoReportingOutputMeta();
  proMeta.setInputFileField( INPUT_FIELD_NAME );
  proMeta.setOutputFileField( OUTPUT_FIELD_NAME );
  proMeta.setOutputProcessorType( type );
  return TransTestFactory.generateTestTransformation( new Variables(), proMeta, REPORTING_STEP_NAME );
}
 
Example #24
Source File: XMLOutputMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheck() throws Exception {
  XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
  xmlOutputMeta.setDefault();
  TransMeta transMeta = mock( TransMeta.class );
  StepMeta stepInfo = mock( StepMeta.class );
  RowMetaInterface prev = mock( RowMetaInterface.class );
  Repository repos = mock( Repository.class );
  IMetaStore metastore = mock( IMetaStore.class );
  RowMetaInterface info = mock( RowMetaInterface.class );
  ArrayList<CheckResultInterface> remarks = new ArrayList<>();
  xmlOutputMeta.check( remarks, transMeta, stepInfo, prev, new String[] { "input" }, new String[] { "output" }, info,
      new Variables(), repos, metastore );
  assertEquals( 2, remarks.size() );
  assertEquals( "Step is receiving info from other steps.", remarks.get( 0 ).getText() );
  assertEquals( "File specifications are not checked.", remarks.get( 1 ).getText() );

  XMLField xmlField = new XMLField();
  xmlField.setFieldName( "aField" );
  xmlField.setType( 1 );
  xmlField.setLength( 10 );
  xmlField.setPrecision( 3 );
  xmlOutputMeta.setOutputFields( new XMLField[] { xmlField } );
  when( prev.size() ).thenReturn( 1 );
  remarks.clear();
  xmlOutputMeta.check( remarks, transMeta, stepInfo, prev, new String[] { "input" }, new String[] { "output" }, info,
      new Variables(), repos, metastore );
  assertEquals( 4, remarks.size() );
  assertEquals( "Step is connected to previous one, receiving 1 fields", remarks.get( 0 ).getText() );
  assertEquals( "All output fields are found in the input stream.", remarks.get( 1 ).getText() );
  assertEquals( "Step is receiving info from other steps.", remarks.get( 2 ).getText() );
  assertEquals( "File specifications are not checked.", remarks.get( 3 ).getText() );

}
 
Example #25
Source File: MQTTConsumerMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckFailAll() {
  List<CheckResultInterface> remarks = new ArrayList<>();
  meta.setKeepAliveInterval( "asdf" );
  meta.setMaxInflight( "asdf" );
  meta.setConnectionTimeout( "asdf" );
  meta.setCleanSession( "asdf" );
  meta.setAutomaticReconnect( "adsf" );
  meta.setMqttVersion( "9" );
  meta.check( remarks, null, null, null, null, null, null, new Variables(), null, null );

  assertEquals( 6, remarks.size() );
  assertEquals( BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotANumber",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + KEEP_ALIVE_INTERVAL ) ),
    remarks.get( 0 ).getText() );
  assertEquals( BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotANumber",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + MAX_INFLIGHT ) ),
    remarks.get( 1 ).getText() );
  assertEquals( BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotANumber",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + CONNECTION_TIMEOUT ) ),
    remarks.get( 2 ).getText() );
  assertEquals( BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotABoolean",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + CLEAN_SESSION ) ),
    remarks.get( 3 ).getText() );
  assertEquals( BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotCorrectVersion",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + MQTT_VERSION ) ),
    remarks.get( 4 ).getText() );
  assertEquals(
    BaseMessages
      .getString( PKG, "MQTTMeta.CheckResult.NotABoolean",
        BaseMessages.getString( PKG, "MQTTDialog.Options." + AUTOMATIC_RECONNECT ) ),
    remarks.get( 5 ).getText() );
}
 
Example #26
Source File: KafkaConsumerTest.java    From pentaho-kafka-consumer with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoInput() throws KettleException {
    TransMeta tm = TransTestFactory.generateTestTransformation(new Variables(), meta, STEP_NAME);

    List<RowMetaAndData> result = TransTestFactory.executeTestTransformation(tm, TransTestFactory.INJECTOR_STEPNAME,
            STEP_NAME, TransTestFactory.DUMMY_STEPNAME, new ArrayList<RowMetaAndData>());

    assertNotNull(result);
    assertEquals(0, result.size());
}
 
Example #27
Source File: BaseStreamStepMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckEqualToBatch() {
  List<CheckResultInterface> remarks = new ArrayList<>();
  meta.setBatchSize( "1" );
  meta.setPrefetchCount( "1" );
  meta.check( remarks, null, null, null, null, null, null, new Variables(), null, null );
  assertEquals( 0, remarks.size() );
}
 
Example #28
Source File: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransWithOneStepIsConsideredUsed() throws Exception {
  TransMeta transMeta = new TransMeta( getClass().getResource( "one-step-trans.ktr" ).getPath() );
  assertEquals( 1, transMeta.getUsedSteps().size() );
  Repository rep = mock( Repository.class );
  ProgressMonitorListener monitor = mock( ProgressMonitorListener.class );
  List<CheckResultInterface> remarks = new ArrayList<>();
  IMetaStore metaStore = mock( IMetaStore.class );
  transMeta.checkSteps( remarks, false, monitor, new Variables(), rep, metaStore );
  assertEquals( 4, remarks.size() );
  for ( CheckResultInterface remark : remarks ) {
    assertEquals( CheckResultInterface.TYPE_RESULT_OK, remark.getType() );
  }
}
 
Example #29
Source File: SalesforceInsertMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFields() throws KettleStepException {
  SalesforceInsertMeta meta = new SalesforceInsertMeta();
  meta.setDefault();
  RowMetaInterface r = new RowMeta();
  meta.getFields( r, "thisStep", null, null, new Variables(), null, null );
  assertEquals( 1, r.size() );
  assertEquals( "Id", r.getFieldNames()[0] );

  meta.setSalesforceIDFieldName( "id_field" );
  r.clear();
  meta.getFields( r, "thisStep", null, null, new Variables(), null, null );
  assertEquals( 1, r.size() );
  assertEquals( "id_field", r.getFieldNames()[0] );
}
 
Example #30
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" ) );
}