Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PDI-14800] Get Filenames step ignores parameters
- Loading branch information
Matt Tucker
committed
Jan 11, 2016
1 parent
eaf4a17
commit 243c149
Showing
3 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
test/org/pentaho/di/trans/steps/getfilenames/GetFileNamesIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" ) ); | ||
|
||
} | ||
} |