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));
}
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());
}
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"));
}
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);
}
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"));
}
Aggregations