Search in sources :

Example 56 with Variables

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();
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) TransMeta(org.pentaho.di.trans.TransMeta) MonetDBDatabaseMeta(org.pentaho.di.core.database.MonetDBDatabaseMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MonetDBDatabaseMeta(org.pentaho.di.core.database.MonetDBDatabaseMeta) Test(org.junit.Test)

Example 57 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 58 with Variables

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());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 59 with Variables

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"));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) CubeOutputMeta(org.pentaho.di.trans.steps.cubeoutput.CubeOutputMeta) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) File(java.io.File) Test(org.junit.Test)

Example 60 with Variables

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"));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) HashMap(java.util.HashMap) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7