Search in sources :

Example 16 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.

the class JobEntryTransTest method testGetTransMeta.

@Test
public void testGetTransMeta() throws KettleException {
    String param1 = "param1";
    String param2 = "param2";
    String param3 = "param3";
    String parentValue1 = "parentValue1";
    String parentValue2 = "parentValue2";
    String childValue3 = "childValue3";
    JobEntryTrans jobEntryTrans = spy(getJobEntryTrans());
    Repository rep = Mockito.mock(Repository.class);
    TransMeta meta = new TransMeta();
    meta.setVariable(param2, "childValue2 should be override");
    meta.setVariable(param3, childValue3);
    Mockito.doReturn(meta).when(rep).loadTransformation(Mockito.eq("test.ktr"), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyBoolean(), Mockito.anyObject());
    VariableSpace parentSpace = new Variables();
    parentSpace.setVariable(param1, parentValue1);
    parentSpace.setVariable(param2, parentValue2);
    jobEntryTrans.setFileName("/home/admin/test.ktr");
    Mockito.doNothing().when(jobEntryTrans).logBasic(Mockito.anyString());
    jobEntryTrans.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    TransMeta transMeta;
    jobEntryTrans.setPassingAllParameters(false);
    transMeta = jobEntryTrans.getTransMeta(rep, null, parentSpace);
    Assert.assertEquals(null, transMeta.getVariable(param1));
    Assert.assertEquals(parentValue2, transMeta.getVariable(param2));
    Assert.assertEquals(childValue3, transMeta.getVariable(param3));
    jobEntryTrans.setPassingAllParameters(true);
    transMeta = jobEntryTrans.getTransMeta(rep, null, parentSpace);
    Assert.assertEquals(parentValue1, transMeta.getVariable(param1));
    Assert.assertEquals(parentValue2, transMeta.getVariable(param2));
    Assert.assertEquals(childValue3, transMeta.getVariable(param3));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) Test(org.junit.Test)

Example 17 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.

the class StepErrorMetaTest method testGetErrorRowMeta.

@Test
public void testGetErrorRowMeta() {
    VariableSpace vars = new Variables();
    vars.setVariable("VarNumberErrors", "nbrErrors");
    vars.setVariable("VarErrorDescription", "errorDescription");
    vars.setVariable("VarErrorFields", "errorFields");
    vars.setVariable("VarErrorCodes", "errorCodes");
    StepErrorMeta testObject = new StepErrorMeta(vars, new StepMeta(), new StepMeta(), "${VarNumberErrors}", "${VarErrorDescription}", "${VarErrorFields}", "${VarErrorCodes}");
    RowMetaInterface result = testObject.getErrorRowMeta(10, "some data was bad", "factId", "BAD131");
    assertNotNull(result);
    assertEquals(4, result.size());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, result.getValueMeta(0).getType());
    assertEquals("nbrErrors", result.getValueMeta(0).getName());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.getValueMeta(1).getType());
    assertEquals("errorDescription", result.getValueMeta(1).getName());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.getValueMeta(2).getType());
    assertEquals("errorFields", result.getValueMeta(2).getName());
    assertEquals(ValueMetaInterface.TYPE_STRING, result.getValueMeta(3).getType());
    assertEquals("errorCodes", result.getValueMeta(3).getName());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 18 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace 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)

Example 19 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.

the class AbstractMetaTest method testEnvironmentSubstitute.

@Test
public void testEnvironmentSubstitute() throws Exception {
    // This is just a delegate method, verify it's called
    VariableSpace vars = mock(VariableSpace.class);
    // This method is reused by the stub to set the mock as the variables object
    meta.setInternalKettleVariables(vars);
    meta.environmentSubstitute("${param}");
    verify(vars, times(1)).environmentSubstitute("${param}");
    String[] params = new String[] { "${param}" };
    meta.environmentSubstitute(params);
    verify(vars, times(1)).environmentSubstitute(params);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with VariableSpace

use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.

the class AbstractMetaTest method testCopyVariablesFrom.

@Test
public void testCopyVariablesFrom() throws Exception {
    assertNull(meta.getVariable("var1"));
    VariableSpace vars = mock(VariableSpace.class);
    when(vars.getVariable("var1")).thenReturn("x");
    when(vars.listVariables()).thenReturn(new String[] { "var1" });
    meta.copyVariablesFrom(vars);
    assertEquals("x", meta.getVariable("var1", "y"));
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) Test(org.junit.Test)

Aggregations

VariableSpace (org.pentaho.di.core.variables.VariableSpace)49 Test (org.junit.Test)21 Variables (org.pentaho.di.core.variables.Variables)14 KettleException (org.pentaho.di.core.exception.KettleException)12 Repository (org.pentaho.di.repository.Repository)10 TransMeta (org.pentaho.di.trans.TransMeta)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)9 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 IOException (java.io.IOException)5 FileObject (org.apache.commons.vfs2.FileObject)5 CurrentDirectoryResolver (org.pentaho.di.core.util.CurrentDirectoryResolver)5 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4