use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class MonetDBBulkLoaderIT method testNoInput.
@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();
}
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class RegexEvalIT method testRegexEval2.
public void testRegexEval2() throws Exception {
String regexStepName = "regexeval";
RegexEvalMeta regexEvalMeta = new RegexEvalMeta();
regexEvalMeta.setScript("\\d(\\d)\\d");
regexEvalMeta.setMatcher("field1");
regexEvalMeta.setResultFieldName("res");
regexEvalMeta.setAllowCaptureGroupsFlag(true);
regexEvalMeta.allocate(1);
// CHECKSTYLE:Indentation:OFF
regexEvalMeta.getFieldName()[0] = "cap";
regexEvalMeta.getFieldType()[0] = ValueMetaInterface.TYPE_INTEGER;
TransMeta transMeta = TransTestFactory.generateTestTransformation(new Variables(), regexEvalMeta, regexStepName);
// Now execute the transformation and get the result from the dummy step.
//
List<RowMetaAndData> result = TransTestFactory.executeTestTransformation(transMeta, TransTestFactory.INJECTOR_STEPNAME, regexStepName, TransTestFactory.DUMMY_STEPNAME, createSourceData());
checkRows(createResultData2(), result);
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class JavaScriptSpecialIT method testDateAdd.
public void testDateAdd() throws Exception {
KettleEnvironment.init();
//
// Create a javascript step
//
String javaScriptStepName = "javascript step";
ScriptValuesMetaMod svm = new ScriptValuesMetaMod();
ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", // PDI-13486
"var new_weekday = dateAdd( input, 'wd', 3 );\n" + "var new_year = dateAdd( input, 'y', 5 );\n" + "var new_month = dateAdd( input, 'm', 5 );\n" + "var new_week = dateAdd( input, 'w', 5 );\n" + "var new_day = dateAdd( input, 'd', 5 );\n" + "var new_hour = dateAdd( input, 'hh', 5 );\n" + "var new_minute = dateAdd( input, 'mi', 5 );\n" + "var new_second = dateAdd( input, 'ss', 5 );\n") };
svm.setJSScripts(js);
svm.setFieldname(new String[] { "new_weekday", "new_year", "new_month", "new_week", "new_day", "new_hour", "new_minute", "new_second" });
svm.setType(new int[] { ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE, ValueMetaInterface.TYPE_DATE });
svm.setRename(new String[] { null, null, null, null, null, null, null, null });
svm.setLength(new int[] { -1, -1, -1, -1, -1, -1, -1, -1 });
svm.setPrecision(new int[] { -1, -1, -1, -1, -1, -1, -1, -1 });
svm.setReplace(new boolean[] { false, false, false, false, false, false, false, false });
svm.setCompatible(false);
TransMeta transMeta = TransTestFactory.generateTestTransformation(new Variables(), svm, javaScriptStepName);
List<RowMetaAndData> result = TransTestFactory.executeTestTransformation(transMeta, TransTestFactory.INJECTOR_STEPNAME, javaScriptStepName, TransTestFactory.DUMMY_STEPNAME, createDateAddData());
checkRows(result, createDateAddResultData());
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class CubeInputStepIntIT method testPDI12897.
@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"));
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testInitializeShareInjectVariables.
@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"));
}
Aggregations