use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class TransMetaTest method testLoadXml.
@Test
public void testLoadXml() throws KettleException {
String directory = "/home/admin";
Node jobNode = Mockito.mock(Node.class);
NodeList nodeList = new NodeList() {
ArrayList<Node> nodes = new ArrayList<>();
{
Node nodeInfo = Mockito.mock(Node.class);
Mockito.when(nodeInfo.getNodeName()).thenReturn(TransMeta.XML_TAG_INFO);
Mockito.when(nodeInfo.getChildNodes()).thenReturn(this);
Node nodeDirectory = Mockito.mock(Node.class);
Mockito.when(nodeDirectory.getNodeName()).thenReturn("directory");
Node child = Mockito.mock(Node.class);
Mockito.when(nodeDirectory.getFirstChild()).thenReturn(child);
Mockito.when(child.getNodeValue()).thenReturn(directory);
nodes.add(nodeDirectory);
nodes.add(nodeInfo);
}
@Override
public Node item(int index) {
return nodes.get(index);
}
@Override
public int getLength() {
return nodes.size();
}
};
Mockito.when(jobNode.getChildNodes()).thenReturn(nodeList);
Repository rep = Mockito.mock(Repository.class);
RepositoryDirectory repDirectory = new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(), "home"), "admin");
Mockito.when(rep.findDirectory(Mockito.eq(directory))).thenReturn(repDirectory);
TransMeta meta = new TransMeta();
VariableSpace variableSpace = Mockito.mock(VariableSpace.class);
Mockito.when(variableSpace.listVariables()).thenReturn(new String[0]);
meta.loadXML(jobNode, null, Mockito.mock(IMetaStore.class), rep, false, variableSpace, Mockito.mock(OverwritePrompter.class));
meta.setInternalKettleVariables(null);
assertEquals(repDirectory.getPath(), meta.getVariable(Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY));
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class ReplaceStringMetaTest method testGetFields.
@Test
public void testGetFields() throws KettleStepException {
ReplaceStringMeta meta = new ReplaceStringMeta();
meta.setFieldInStream(new String[] { FIELD_NAME });
meta.setFieldOutStream(new String[] { FIELD_NAME });
ValueMetaInterface inputFieldMeta = mock(ValueMetaInterface.class);
when(inputFieldMeta.getStringEncoding()).thenReturn(ENCODING_NAME);
RowMetaInterface inputRowMeta = mock(RowMetaInterface.class);
when(inputRowMeta.searchValueMeta(anyString())).thenReturn(inputFieldMeta);
StepMeta nextStep = mock(StepMeta.class);
VariableSpace space = mock(VariableSpace.class);
Repository repository = mock(Repository.class);
IMetaStore metaStore = mock(IMetaStore.class);
meta.getFields(inputRowMeta, "test", null, nextStep, space, repository, metaStore);
ArgumentCaptor<ValueMetaInterface> argument = ArgumentCaptor.forClass(ValueMetaInterface.class);
verify(inputRowMeta).addValueMeta(argument.capture());
assertEquals(ENCODING_NAME, argument.getValue().getStringEncoding());
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class TextFileInputMetaTest method setUp.
@Before
public void setUp() throws Exception {
NamedClusterEmbedManager manager = mock(NamedClusterEmbedManager.class);
TransMeta parentTransMeta = mock(TransMeta.class);
doReturn(manager).when(parentTransMeta).getNamedClusterEmbedManager();
StepMeta parentStepMeta = mock(StepMeta.class);
doReturn(parentTransMeta).when(parentStepMeta).getParentTransMeta();
inputMeta = new TextFileInputMeta();
inputMeta.setParentStepMeta(parentStepMeta);
inputMeta = spy(inputMeta);
variableSpace = mock(VariableSpace.class);
doReturn("<def>").when(variableSpace).environmentSubstitute(anyString());
doReturn(FILE_NAME_VALID_PATH).when(variableSpace).environmentSubstitute(FILE_NAME_VALID_PATH);
FileObject mockedFileObject = mock(FileObject.class);
doReturn(mockedFileObject).when(inputMeta).getFileObject(anyString(), eq(variableSpace));
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class TextFileOutputTest method doOutput.
private List<Throwable> doOutput(TextFileField[] textFileField, List<Object[]> rows, String pathToFile, String endedLine, Boolean isHeaderEnabled, Boolean isDoNotOpenNewFileInit, Boolean append) throws KettleException {
TextFileOutputData textFileOutputData = new TextFileOutputData();
TextFileOutput textFileOutput = new TextFileOutputTestHandler(stepMockHelper.stepMeta, textFileOutputData, 0, stepMockHelper.transMeta, stepMockHelper.trans);
// init step meta and process step meta should be the same in this case
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isDoNotOpenNewFileInit()).thenReturn(isDoNotOpenNewFileInit);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isFileAppended()).thenReturn(append);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isHeaderEnabled()).thenReturn(isHeaderEnabled);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getFileName()).thenReturn(pathToFile);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.buildFilename(Mockito.anyString(), Mockito.anyString(), ((VariableSpace) Mockito.anyObject()), Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyBoolean(), (TextFileOutputMeta) Mockito.anyObject())).thenReturn(pathToFile);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getOutputFields()).thenReturn(textFileField);
textFileOutput.init(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
// Process rows
RowSet rowSet = stepMockHelper.getMockInputRowSet(rows);
RowMetaInterface inputRowMeta = Mockito.mock(RowMetaInterface.class);
textFileOutput.setInputRowMeta(inputRowMeta);
Mockito.when(rowSet.getRowWait(Mockito.anyInt(), (TimeUnit) Mockito.anyObject())).thenReturn(rows.isEmpty() ? null : rows.iterator().next());
Mockito.when(rowSet.getRowMeta()).thenReturn(inputRowMeta);
Mockito.when(inputRowMeta.clone()).thenReturn(inputRowMeta);
for (int i = 0; i < textFileField.length; i++) {
String name = textFileField[i].getName();
ValueMetaString valueMetaString = new ValueMetaString(name);
Mockito.when(inputRowMeta.getValueMeta(i)).thenReturn(valueMetaString);
Mockito.when(inputRowMeta.indexOfValue(name)).thenReturn(i);
}
textFileOutput.addRowSetToInputRowSets(rowSet);
textFileOutput.addRowSetToOutputRowSets(rowSet);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.getEndedLine()).thenReturn(endedLine);
Mockito.when(stepMockHelper.processRowsStepMetaInterface.isFastDump()).thenReturn(true);
for (int i = 0; i < rows.size(); i++) {
((TextFileOutputTestHandler) textFileOutput).setRow(rows.get(i));
textFileOutput.processRow(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
}
((TextFileOutputTestHandler) textFileOutput).setRow(null);
textFileOutput.processRow(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
textFileOutput.dispose(stepMockHelper.processRowsStepMetaInterface, textFileOutputData);
return ((TextFileOutputTestHandler) textFileOutput).errors;
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class JobExecutorMetaTest method testLoadJobMeta.
@Test
public void testLoadJobMeta() throws KettleException {
String param1 = "param1";
String param2 = "param2";
String param3 = "param3";
String parentValue1 = "parentValue1";
String parentValue2 = "parentValue2";
String childValue3 = "childValue3";
JobExecutorMeta jobExecutorMeta = spy(new JobExecutorMeta());
Repository repository = Mockito.mock(Repository.class);
JobMeta meta = new JobMeta();
meta.setVariable(param2, "childValue2 should be override");
meta.setVariable(param3, childValue3);
Mockito.doReturn(meta).when(repository).loadJob(Mockito.eq("test.kjb"), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyObject());
VariableSpace parentSpace = new Variables();
parentSpace.setVariable(param1, parentValue1);
parentSpace.setVariable(param2, parentValue2);
jobExecutorMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
jobExecutorMeta.setFileName("/home/admin/test.kjb");
JobMeta jobMeta;
jobExecutorMeta.getParameters().setInheritingAllVariables(false);
jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
Assert.assertEquals(null, jobMeta.getVariable(param1));
Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
jobExecutorMeta.getParameters().setInheritingAllVariables(true);
jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
Assert.assertEquals(parentValue1, jobMeta.getVariable(param1));
Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
}
Aggregations