Skip to content

Commit

Permalink
[PDI-14800] Get Filenames step ignores parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Tucker committed Jan 11, 2016
1 parent eaf4a17 commit 243c149
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
Expand Up @@ -312,7 +312,7 @@ public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
data.nrStepFields = data.outputRowMeta.size();

if ( !meta.isFileField() ) {
data.files = meta.getFileList( getTransMeta() );
data.files = meta.getFileList( this );
data.filessize = data.files.nrOfFiles();
handleMissingFiles();
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/org/pentaho/di/trans/TransTestFactory.java
Expand Up @@ -139,9 +139,25 @@ public static TransMeta generateTestTransformationError( VariableSpace parent, S

public static List<RowMetaAndData> executeTestTransformation( TransMeta transMeta, String injectorStepname,
String testStepname, String dummyStepname, List<RowMetaAndData> inputData ) throws KettleException {
return executeTestTransformation( transMeta, injectorStepname, testStepname,
dummyStepname, inputData, null, null );
}
public static List<RowMetaAndData> executeTestTransformation( TransMeta transMeta, String injectorStepname,
String testStepname, String dummyStepname, List<RowMetaAndData> inputData,
VariableSpace runTimeVariables, VariableSpace runTimeParameters ) throws KettleException {
// Now execute the transformation...
Trans trans = new Trans( transMeta );

trans.initializeVariablesFrom( runTimeVariables );
if ( runTimeParameters != null ) {
for ( String param : trans.listParameters() ) {
String value = runTimeParameters.getVariable( param );
if ( value != null ) {
trans.setParameterValue( param, value );
transMeta.setParameterValue( param, value );
}
}
}
trans.prepareExecution( null );

// Capture the rows that come out of the dummy step...
Expand Down
@@ -0,0 +1,94 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

package org.pentaho.di.trans.steps.getfilenames;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.RowMetaAndData;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.variables.Variables;
import org.pentaho.di.trans.TransHopMeta;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.TransTestFactory;

public class GetFileNamesIntTest {

private static final String STEPNAME = "TestGetFileNames_Step";

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

@BeforeClass
public static void setUpBeforeClass() throws KettleException {
KettleEnvironment.init( false );
}

@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() );

// Create a file that will be found in the GetFileNames step
String expectedFilename = "PDI14800_test.tmp";
tempFolder.newFile( expectedFilename );

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" ) );

}
}

0 comments on commit 243c149

Please sign in to comment.