use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class GetVariableMetaTest method testGetValueMetaPlugin.
@Test
public void testGetValueMetaPlugin() throws KettleStepException {
GetVariableMeta meta = new GetVariableMeta();
meta.setDefault();
FieldDefinition field = new FieldDefinition();
field.setFieldName("outputField");
field.setVariableString(String.valueOf(2000000L));
field.setFieldType(ValueMetaInterface.TYPE_TIMESTAMP);
meta.setFieldDefinitions(new FieldDefinition[] { field });
RowMetaInterface rowMeta = new RowMeta();
meta.getFields(rowMeta, "stepName", null, null, new Variables(), null, null);
assertNotNull(rowMeta);
assertEquals(1, rowMeta.size());
assertEquals("outputField", rowMeta.getFieldNames()[0]);
assertEquals(ValueMetaInterface.TYPE_TIMESTAMP, rowMeta.getValueMeta(0).getType());
assertTrue(rowMeta.getValueMeta(0) instanceof ValueMetaTimestamp);
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class StepWithMappingMetaTest method activateParamsTest.
@Test
@PrepareForTest(StepWithMappingMeta.class)
public void activateParamsTest() throws Exception {
String childParam = "childParam";
String childValue = "childValue";
String paramOverwrite = "paramOverwrite";
String parentValue = "parentValue";
VariableSpace parent = new Variables();
parent.setVariable(paramOverwrite, parentValue);
TransMeta childVariableSpace = new TransMeta();
childVariableSpace.setParameterValue(childParam, childValue);
String[] parameters = childVariableSpace.listParameters();
StepWithMappingMeta.activateParams(childVariableSpace, childVariableSpace, parent, parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, childValue });
Assert.assertEquals(childValue, childVariableSpace.getVariable(childParam));
Assert.assertEquals(parentValue, childVariableSpace.getVariable(paramOverwrite));
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class StepWithMappingMetaTest method loadMappingMeta.
@Test
public void loadMappingMeta() throws Exception {
String variablePath = "Internal.Entry.Current.Directory";
String virtualDir = "/testFolder/CDA-91";
String fileName = "testTrans.ktr";
VariableSpace variables = new Variables();
StepMeta stepMeta = new StepMeta();
TransMeta parentTransMeta = new TransMeta();
stepMeta.setParentTransMeta(parentTransMeta);
RepositoryDirectoryInterface repositoryDirectory = Mockito.mock(RepositoryDirectoryInterface.class);
when(repositoryDirectory.toString()).thenReturn(virtualDir);
stepMeta.getParentTransMeta().setRepositoryDirectory(repositoryDirectory);
StepWithMappingMeta mappingMetaMock = mock(StepWithMappingMeta.class);
when(mappingMetaMock.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.FILENAME);
when(mappingMetaMock.getFileName()).thenReturn("${" + variablePath + "}/" + fileName);
when(mappingMetaMock.getParentStepMeta()).thenReturn(stepMeta);
// mock repo and answers
Repository rep = mock(Repository.class);
Mockito.doAnswer(new Answer<TransMeta>() {
@Override
public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
final String originalArgument = (String) (invocation.getArguments())[0];
// be sure that the variable was replaced by real path
assertEquals(virtualDir, originalArgument);
return null;
}
}).when(rep).findDirectory(anyString());
Mockito.doAnswer(new Answer<TransMeta>() {
@Override
public TransMeta answer(final InvocationOnMock invocation) throws Throwable {
final String originalArgument = (String) (invocation.getArguments())[0];
// be sure that transformation name was resolved correctly
assertEquals(fileName, originalArgument);
return mock(TransMeta.class);
}
}).when(rep).loadTransformation(anyString(), any(RepositoryDirectoryInterface.class), any(ProgressMonitorListener.class), anyBoolean(), anyString());
StepWithMappingMeta.loadMappingMeta(mappingMetaMock, rep, null, variables, true);
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class SubtransExecutorTest method stopsAll.
@Test
public void stopsAll() throws KettleException {
TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
LoggingObjectInterface loggingObject = new LoggingObject("anything");
Trans parentTrans = new Trans(parentMeta, loggingObject);
SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "");
subtransExecutor.running = Mockito.spy(subtransExecutor.running);
RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
subtransExecutor.execute(rows);
verify(subtransExecutor.running).add(any());
subtransExecutor.stop();
assertTrue(subtransExecutor.running.isEmpty());
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class BaseExcelParsingTest method setFields.
/**
* Declare fields for test.
*/
protected void setFields(ExcelInputField... fields) throws Exception {
meta.setField(fields);
meta.getFields(data.outputRowMeta, meta.getName(), null, null, new Variables(), null, null);
}
Aggregations