下面列出了org.apache.hadoop.hbase.filter.RegexStringComparator#org.pentaho.di.core.variables.VariableSpace 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Before
public void setup() throws KettlePluginException {
mockSpace = mock( VariableSpace.class );
doReturn("N" ).when( mockSpace ).getVariable( any(), anyString() );
rowMeta = spy( new RowMeta() );
memoryGroupByMeta = spy( new MemoryGroupByMeta() );
mockStatic( ValueMetaFactory.class );
when( ValueMetaFactory.createValueMeta( anyInt() ) ).thenCallRealMethod();
when( ValueMetaFactory.createValueMeta( anyString(), anyInt() ) ).thenCallRealMethod();
when( ValueMetaFactory.createValueMeta( "maxDate", 3, -1, -1 ) ).thenReturn( new ValueMetaDate( "maxDate" ) );
when( ValueMetaFactory.createValueMeta( "minDate", 3, -1, -1 ) ).thenReturn( new ValueMetaDate( "minDate" ) );
when( ValueMetaFactory.createValueMeta( "countDate", 5, -1, -1 ) ).thenReturn( new ValueMetaInteger( "countDate" ) );
when( ValueMetaFactory.getValueMetaName( 3 ) ).thenReturn( "Date" );
when( ValueMetaFactory.getValueMetaName( 5 ) ).thenReturn( "Integer" );
}
@Test
@PrepareForTest( StepWithMappingMeta.class )
public void activateParamsTest() throws Exception {
String childParam = "childParam";
String childValue = "childValue";
String paramOverwrite = "paramOverwrite";
String parentValue = "parentValue";
String stepValue = "stepValue";
VariableSpace parent = new Variables();
parent.setVariable( paramOverwrite, parentValue );
TransMeta childVariableSpace = new TransMeta();
childVariableSpace.addParameterDefinition( childParam, "", "" );
childVariableSpace.setParameterValue( childParam, childValue );
String[] parameters = childVariableSpace.listParameters();
StepWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parent,
parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, stepValue }, true );
Assert.assertEquals( childValue, childVariableSpace.getVariable( childParam ) );
// the step parameter prevails
Assert.assertEquals( stepValue, childVariableSpace.getVariable( paramOverwrite ) );
}
/**
* Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
* what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
* For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
* that.
*
* @param space
* the variable space to use
* @param definitions
* @param resourceNamingInterface
* @param repository
* The repository to optionally load other resources from (to be converted to XML)
* @param metaStore
* the metaStore in which non-kettle metadata could reside.
*
* @return the filename of the exported resource
*/
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
try {
// The object that we're modifying here is a copy of the original!
// So let's change the filename from relative to absolute by grabbing the file object...
// In case the name of the file comes from previous steps, forget about this!
//
if ( !filefield ) {
for ( int i = 0; i < fileName.length; i++ ) {
FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName[i] ), space );
fileName[i] = resourceNamingInterface.nameResource( fileObject, space, Utils.isEmpty( fileMask[i] ) );
}
}
return null;
} catch ( Exception e ) {
throw new KettleException( e );
}
}
public ValueMetaInterface toValueMeta( String fieldOriginStepName, VariableSpace vspace ) throws KettlePluginException {
int type = getType();
if ( type == ValueMetaInterface.TYPE_NONE ) {
type = ValueMetaInterface.TYPE_STRING;
}
ValueMetaInterface v =
ValueMetaFactory.createValueMeta( vspace != null ? vspace.environmentSubstitute( getName() ) : getName(), type );
v.setLength( getLength() );
v.setPrecision( getPrecision() );
v.setOrigin( fieldOriginStepName );
v.setConversionMask( getFormat() );
v.setDecimalSymbol( getDecimalSymbol() );
v.setGroupingSymbol( getGroupSymbol() );
v.setCurrencySymbol( getCurrencySymbol() );
v.setTrimType( getTrimType() );
return v;
}
@Test public void testTopLevelArrayStructureWithObjects() throws Exception {
List<MongoDbOutputMeta.MongoField> paths = asList( mf( "field1", true, "[0]" ), mf( "field2", true, "[1]" ) );
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.ARRAY, false );
assertEquals( JSON.serialize( result ), "[ { \"field1\" : \"value1\"} , { \"field2\" : 12}]" );
}
public void getFields(RowMetaInterface r, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) {
/*
* Adicionar los campos de salida, estos son los que se toman luego en el
* metodo processRow en la clase CiviInput. Note que esta clase es tambien
* un atributo privado de CiviInput Aqui decimos el tipo de dato del campo
*/
for (String cField : civiCrmKeyList) {
try {
// Añadido una verifición para evitar que campos ----------> Line no existentes queden fuera de la salida del paso al
// no encontrarse en el listado de campos devuelto por CiviCRM. En este caso se asume
// que el campo es una cadena automáticamente
ValueMetaInterface v = new ValueMeta(outputMap.get(cField), (civiCrmListingFields.get(cField) != null) ? civiCrmListingFields.get(cField).getMetaInterfaceType() : ValueMetaInterface.TYPE_STRING);
v.setOrigin(origin);
r.addValueMeta(v);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public String calculateCompleteFilename( VariableSpace space ) {
String baseFilePath = space.environmentSubstitute( basePath );
if ( StringUtils.isEmpty( baseFilePath ) ) {
// See if the base path environment variable is set
//
baseFilePath = space.getVariable( DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH );
}
if ( StringUtils.isEmpty( baseFilePath ) ) {
baseFilePath = "";
}
if ( StringUtils.isNotEmpty( baseFilePath ) ) {
if ( !baseFilePath.endsWith( File.separator ) ) {
baseFilePath += File.separator;
}
}
return baseFilePath + transFilename;
}
/**
* Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
* what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
* For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
* that.
*
* @param space
* the variable space to use
* @param definitions
* @param resourceNamingInterface
* @param repository
* The repository to optionally load other resources from (to be converted to XML)
* @param metaStore
* the metaStore in which non-kettle metadata could reside.
*
* @return the filename of the exported resource
*/
@Override
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
try {
// The object that we're modifying here is a copy of the original!
// So let's change the filename from relative to absolute by grabbing the file object...
// In case the name of the file comes from previous steps, forget about this!
//
if ( !acceptingFilenames ) {
// Replace the filename ONLY (folder or filename)
//
for ( int i = 0; i < fileName.length; i++ ) {
FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName[i] ), space );
fileName[i] = resourceNamingInterface.nameResource( fileObject, space, Utils.isEmpty( fileMask[i] ) );
}
}
return null;
} catch ( Exception e ) {
throw new KettleException( e );
}
}
@Test
public void testGetFields() throws KettleStepException {
ReplaceStringMeta meta = new ReplaceStringMeta();
meta.setFieldInStream( new String[] { FIELD_NAME } );
meta.setFieldOutStream( new String[] { FIELD_NAME } );
ValueMetaInterface inputFieldMeta = mock( ValueMetaInterface.class );
when( inputFieldMeta.getStringEncoding() ).thenReturn( ENCODING_NAME );
RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
when( inputRowMeta.searchValueMeta( anyString() ) ).thenReturn( inputFieldMeta );
StepMeta nextStep = mock( StepMeta.class );
VariableSpace space = mock( VariableSpace.class );
Repository repository = mock( Repository.class );
IMetaStore metaStore = mock( IMetaStore.class );
meta.getFields( inputRowMeta, "test", null, nextStep, space, repository, metaStore );
ArgumentCaptor<ValueMetaInterface> argument = ArgumentCaptor.forClass( ValueMetaInterface.class );
verify( inputRowMeta ).addValueMeta( argument.capture() );
assertEquals( ENCODING_NAME, argument.getValue().getStringEncoding() );
}
@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" ) );
}
@Override
public void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
for ( SasInputField field : outputFields ) {
try {
ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getRename(), field.getType() );
valueMeta.setLength( field.getLength(), field.getPrecision() );
valueMeta.setDecimalSymbol( field.getDecimalSymbol() );
valueMeta.setGroupingSymbol( field.getGroupingSymbol() );
valueMeta.setConversionMask( field.getConversionMask() );
valueMeta.setTrimType( field.getTrimType() );
valueMeta.setOrigin( name );
row.addValueMeta( valueMeta );
} catch ( Exception e ) {
throw new KettleStepException( e );
}
}
}
public static Object percent2( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB, VariableSpace space ) throws KettleValueException {
if ( dataA == null || dataB == null ) {
return null;
}
switch ( metaA.getType() ) {
case ValueMetaInterface.TYPE_NUMBER:
return new Double( metaA.getNumber( dataA ).doubleValue()
- divideDoubles( multiplyDoubles( metaA.getNumber( dataA ), metaB.getNumber( dataB ) ), 100.0D ) );
case ValueMetaInterface.TYPE_INTEGER:
return new Long( metaA.getInteger( dataA ).longValue()
- divideLongs( multiplyLongs( metaA.getInteger( dataA ), metaB.getInteger( dataB ) ), 100L ) );
case ValueMetaInterface.TYPE_BIGNUMBER:
return metaA.getBigNumber( dataA ).subtract(
divideBigDecimals( multiplyBigDecimals(
metaB.getBigNumber( dataB ), metaA.getBigNumber( dataA ), null ), new BigDecimal( 100 ), space ) );
default:
throw new KettleValueException( "The 'A-B%' function only works on numeric data" );
}
}
/**
* Reset this field. Should be called prior to processing a new field value from the avro file
*
* @param space environment variables (values that environment variables resolve to cannot contain "."s)
*/
public void reset( VariableSpace space ) {
m_tempParts.clear();
for ( String part : m_pathParts ) {
if ( space == null ) {
m_tempParts.add( part );
} else {
m_tempParts.add( space.environmentSubstitute( part ) );
}
}
// reset sub fields
for ( AvroInputField f : m_subFields ) {
resetField( f, space );
}
}
private DatabaseLookupMeta mockStepMeta() throws KettleStepException {
DatabaseLookupMeta stepMeta = smh.initStepMetaInterface;
doReturn( mock( DatabaseMeta.class ) ).when( stepMeta ).getDatabaseMeta();
doReturn( new String[] { "=" } ).when( stepMeta ).getKeyCondition();
doCallRealMethod().when( stepMeta ).getFields( any( RowMetaInterface.class ), anyString(),
any( RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ),
any( IMetaStore.class ) );
doReturn( new String[] { "value" } ).when( stepMeta ).getReturnValueNewName();
doReturn( new int[] { ValueMetaInterface.TYPE_STRING } ).when( stepMeta ).getReturnValueDefaultType();
doReturn( true ).when( stepMeta ).isCached();
doReturn( true ).when( stepMeta ).isLoadingAllDataInCache();
doReturn( new String[] { "id" } ).when( stepMeta ).getStreamKeyField1();
doReturn( new String[] { null } ).when( stepMeta ).getStreamKeyField2();
doReturn( new String[] { "id" } ).when( stepMeta ).getTableKeyField();
doReturn( new String[] { "value" } ).when( stepMeta ).getReturnValueField();
doReturn( new String[] { "" } ).when( stepMeta ).getReturnValueDefault();
doReturn( new int[] { ValueMetaInterface.TYPE_STRING } ).when( stepMeta ).getReturnValueDefaultType();
when( stepMeta.getStreamKeyField2() ).thenReturn( new String[]{ "a", "b", "c" } );
return stepMeta;
}
public void check( List<CheckResultInterface> remarks, JobMeta jobMeta, VariableSpace space,
Repository repository, IMetaStore metaStore ) {
JobEntryValidatorUtils.andValidator().validate( this, "serverName", remarks,
AndValidator.putValidators( JobEntryValidatorUtils.notBlankValidator() ) );
JobEntryValidatorUtils.andValidator().validate(
this, "targetDirectory", remarks, AndValidator.putValidators( JobEntryValidatorUtils.notBlankValidator(),
JobEntryValidatorUtils.fileExistsValidator() ) );
JobEntryValidatorUtils.andValidator().validate( this, "userName", remarks,
AndValidator.putValidators( JobEntryValidatorUtils.notBlankValidator() ) );
JobEntryValidatorUtils.andValidator().validate( this, "password", remarks,
AndValidator.putValidators( JobEntryValidatorUtils.notNullValidator() ) );
}
@Override public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore )
throws KettleStepException {
ValueMetaInterface keyValueMeta = new ValueMetaString( space.environmentSubstitute( keyField ) );
keyValueMeta.setOrigin( name );
inputRowMeta.addValueMeta( keyValueMeta );
ValueMetaInterface messageValueMeta = new ValueMetaString( space.environmentSubstitute( messageField ) );
messageValueMeta.setOrigin( name );
inputRowMeta.addValueMeta( messageValueMeta );
}
@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info,
StepMeta nextStep, VariableSpace space) throws KettleStepException {
for (int i = 0; i < odpsFields.size(); i++) {
ValueMetaInterface v = new ValueMeta(odpsFields.get(i).getName().toLowerCase(),
ValueMetaInterface.TYPE_STRING);
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
}
}
@Override
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) {
if ( !Utils.isEmpty( resultfieldName ) ) {
ValueMetaInterface v = new ValueMetaInteger( resultfieldName );
v.setLength( ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0 );
v.setOrigin( name );
r.addValueMeta( v );
}
}
public static TransMeta generateTestTransformation( VariableSpace parent, StepMetaInterface oneMeta,
String oneStepname ) {
TransMeta previewMeta = new TransMeta( parent );
// First the injector step...
StepMeta zero = getInjectorStepMeta();
previewMeta.addStep( zero );
// Then the middle step to test...
//
StepMeta one = new StepMeta( registry.getPluginId( StepPluginType.class, oneMeta ), oneStepname, oneMeta );
one.setLocation( 150, 50 );
one.setDraw( true );
previewMeta.addStep( one );
// Then we add the dummy step to read the results from
StepMeta two = getReadStepMeta();
previewMeta.addStep( two );
// Add the hops between the 3 steps.
TransHopMeta zeroOne = new TransHopMeta( zero, one );
previewMeta.addTransHop( zeroOne );
TransHopMeta oneTwo = new TransHopMeta( one, two );
previewMeta.addTransHop( oneTwo );
return previewMeta;
}
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
for ( int i = 0; i < this.fieldname.length; i++ ) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta( this.fieldname[i], type[i], length[i], precision[i] );
inputRowMeta.addValueMeta( v );
} catch ( KettlePluginException e ) {
throw new KettleStepException( e );
}
}
}
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
// We don't have any input fields here in "r" as they are all info fields.
// So we just take the info fields.
//
if ( info != null ) {
if ( info.length > 0 && info[0] != null ) {
r.mergeRowMeta( info[0] );
}
}
}
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
RowMetaInterface rowMeta = UnitTestResult.getRowMeta();
int index = 0;
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( transformationNameField ) );
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( unitTestNameField ) );
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( dataSetNameField ) );
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( stepNameField ) );
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( errorField ) );
rowMeta.getValueMeta( index++ ).setName( space.environmentSubstitute( commentField ) );
inputRowMeta.clear();
inputRowMeta.addRowMeta( rowMeta );
}
public static List<DatabaseMeta> getAvailableDatabases( Repository repository ) throws KettleException {
List<DatabaseMeta> list = new ArrayList<DatabaseMeta>();
// Load database connections from the central repository if we're connected to one
//
if ( repository != null ) {
ObjectId[] databaseIDs = repository.getDatabaseIDs( false );
for ( ObjectId databaseId : databaseIDs ) {
list.add( repository.loadDatabaseMeta( databaseId, null ) );
}
}
// We need to share a default VariableSpace (env vars) with these objects...
//
VariableSpace space = Variables.getADefaultVariableSpace();
// Also load from the standard shared objects file
//
SharedObjects sharedObjects = new SharedObjects( Const.getSharedObjectsFile() );
Collection<SharedObjectInterface> localSharedObjects = sharedObjects.getObjectsMap().values();
for ( SharedObjectInterface localSharedObject : localSharedObjects ) {
if ( localSharedObject instanceof DatabaseMeta ) {
DatabaseMeta databaseMeta = (DatabaseMeta) localSharedObject;
// Only add a local database if it doesn't exist in the central repository
//
if ( !list.contains( databaseMeta ) ) {
list.add( databaseMeta );
// To allow these connections to be parameterized
//
databaseMeta.initializeVariablesFrom( space );
}
}
}
return list;
}
public static PythonSession acquirePySession( Object requester, LogChannelInterface log, VariableSpace vars )
throws KettleException {
// check availability first...
initPython( vars, log );
PythonSession session;
try {
session = PythonSession.acquireSession( requester );
} catch ( SessionException ex ) {
throw new KettleException( ex );
}
session.setLog( log );
return session;
}
private void initiateVariables( String fileContent, BaseFileField[] baseFileFields, int fileFormat ) throws Exception {
//reader
reader = new InputStreamReader( new ByteArrayInputStream( fileContent.getBytes( StandardCharsets.UTF_8 ) ) );
//Content
setInternalState( content, "header", true );
setInternalState( content, "nrHeaderLines", 1 );
setInternalState( content, "escapeCharacter", "" );
//baseFileInputFiles
setInternalState( baseFileInputFiles, "fileName", new String[]{} );
setInternalState( baseFileInputFiles, "fileMask", new String[]{} );
setInternalState( baseFileInputFiles, "excludeFileMask", new String[]{} );
setInternalState( baseFileInputFiles, "fileRequired", new String[]{} );
when( baseFileInputFiles.includeSubFolderBoolean() ).thenReturn( new boolean[] {} );
when( FileInputList.createFilePathList( any( VariableSpace.class ),
any( String[].class ), any( String[].class ), any( String[].class ), any( String[].class ),
any( boolean[].class ) ) ).thenReturn( new String[]{""} );
//meta
when( meta.getInputFields() ).thenReturn( baseFileFields );
doCallRealMethod().when( meta ).getFields( any( RowMetaInterface.class ), anyString(), any( RowMetaInterface[].class ),
any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ), any( IMetaStore.class ) );
setInternalState( meta, "inputFields", baseFileFields );
setInternalState( meta, "content", content );
when( meta.clone() ).thenReturn( meta );
setInternalState( content, "separator", "," );
setInternalState( content, "enclosure", "\"" );
when( meta.getEnclosure() ).thenReturn( "\"" );
when( meta.getFileFormatTypeNr() ).thenReturn( fileFormat );
setInternalState( content, "fileType", "CSV" );
setInternalState( meta, "inputFiles", baseFileInputFiles );
setInternalState( meta, "errorHandling", baseFileErrorHandling );
setInternalState( meta, "additionalOutputFields", baseFileInputAdditionalField );
//transmeta
when( transMeta.environmentSubstitute( "," ) ).thenReturn( "," );
when( transMeta.environmentSubstitute( "\"" ) ).thenReturn( "\"" );
when( transMeta.getObjectType() ).thenReturn( LoggingObjectType.TRANSMETA );
//textFileCSVImportProgressDialog
textFileCSVImportProgressDialog = spy( new TextFileCSVImportProgressDialog(
shell, meta, transMeta, reader, 100, true ) );
}
/**
* Set the variable that will be used by Vfs to set the FileSystemOptions for the file system.
* @param nameSpace The namespace used by the getFileObject method to access VFS.
* @param embeddedMetastoreProviderKey The key to the embeddedMetastore from the AbstraceMeta
*/
public void passEmbeddedMetastoreKey( VariableSpace nameSpace, String embeddedMetastoreProviderKey ) {
if ( nameSpace != null ) {
if ( embeddedMetastoreProviderKey != null ) {
nameSpace.setVariable( "vfs.hc.embeddedMetastoreKey", embeddedMetastoreProviderKey );
}
}
}
@Test
public void testVerifyNoPreviousStep() {
LoadFileInputMeta spy = spy( new LoadFileInputMeta() );
FileInputList fileInputList = mock( FileInputList.class );
List<FileObject> files = when( mock( List.class ).size() ).thenReturn( 1 ).getMock();
doReturn( files ).when( fileInputList ).getFiles();
doReturn( fileInputList ).when( spy ).getFiles( any( VariableSpace.class ) );
@SuppressWarnings( "unchecked" )
List<CheckResultInterface> validationResults = mock( List.class );
// Check we do not get validation errors
doAnswer( new Answer<Object>() {
@Override
public Object answer( InvocationOnMock invocation ) throws Throwable {
if ( ( (CheckResultInterface) invocation.getArguments()[0] ).getType() != CheckResultInterface.TYPE_RESULT_OK ) {
TestCase.fail( "We've got validation error" );
}
return null;
}
} ).when( validationResults ).add( any( CheckResultInterface.class ) );
spy.check( validationResults, mock( TransMeta.class ), mock( StepMeta.class ), mock( RowMetaInterface.class ),
new String[] {}, new String[] { "File content", "File size" }, mock( RowMetaInterface.class ),
mock( VariableSpace.class ), mock( Repository.class ), mock( IMetaStore.class ) );
}
@Before
public void setup() throws FileSystemException {
fs = VFS.getManager();
filesPath = '/' + this.getClass().getPackage().getName().replace( '.', '/' ) + "/files/";
transName = "LoadFileInput";
transMeta = new TransMeta();
transMeta.setName( transName );
trans = new Trans( transMeta );
stepMetaInterface = spy( new LoadFileInputMeta() );
stepInputFiles = new FileInputList();
Mockito.doReturn( stepInputFiles ).when( stepMetaInterface ).getFiles( any( VariableSpace.class ) );
String stepId = PluginRegistry.getInstance().getPluginId( StepPluginType.class, stepMetaInterface );
stepMeta = new StepMeta( stepId, "Load File Input", stepMetaInterface );
transMeta.addStep( stepMeta );
stepDataInterface = new LoadFileInputData();
stepCopyNr = 0;
stepLoadFileInput = new LoadFileInput( stepMeta, stepDataInterface, stepCopyNr, transMeta, trans );
assertSame( stepMetaInterface, stepMeta.getStepMetaInterface() );
runtimeSMI = stepMetaInterface;
runtimeSDI = runtimeSMI.getStepData();
inputField = new LoadFileInputField();
((LoadFileInputMeta) runtimeSMI).setInputFields( new LoadFileInputField[] { inputField } );
stepLoadFileInput.init( runtimeSMI, runtimeSDI );
}
private IfNullMeta mockProcessRowMeta() throws KettleStepException {
IfNullMeta processRowMeta = smh.processRowsStepMetaInterface;
doReturn( createFields( "null-field", "empty-field", "space-field" ) ).when( processRowMeta ).getFields();
doReturn( "replace-value" ).when( processRowMeta ).getReplaceAllByValue();
doCallRealMethod().when( processRowMeta ).getFields( any( RowMetaInterface.class ), anyString(), any(
RowMetaInterface[].class ), any( StepMeta.class ), any( VariableSpace.class ), any( Repository.class ), any(
IMetaStore.class ) );
return processRowMeta;
}
protected VariableSpace getVariableSpace( CheckResultSourceInterface source, String propertyName,
List<CheckResultInterface> remarks, ValidatorContext context ) {
Object obj = context.get( KEY_VARIABLE_SPACE );
if ( obj instanceof VariableSpace ) {
return (VariableSpace) obj;
} else {
JobEntryValidatorUtils.addGeneralRemark(
source, propertyName, getName(), remarks, "messages.failed.missingKey",
CheckResultInterface.TYPE_RESULT_ERROR );
return null;
}
}