use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class RestMetaTest method testStepChecks.
@Test
public void testStepChecks() {
RestMeta meta = new RestMeta();
List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
TransMeta transMeta = new TransMeta();
StepMeta step = new StepMeta();
RowMetaInterface prev = new RowMeta();
RowMetaInterface info = new RowMeta();
String[] input = new String[0];
String[] output = new String[0];
VariableSpace variables = new Variables();
Repository repo = null;
IMetaStore metaStore = null;
// In a default configuration, it's expected that some errors will occur.
// For this, we'll grab a baseline count of the number of errors
// as the error count should decrease as we change configuration settings to proper values.
remarks.clear();
meta.check(remarks, transMeta, step, prev, input, output, info, variables, repo, metaStore);
final int errorsDefault = getCheckResultErrorCount(remarks);
assertTrue(errorsDefault > 0);
// Setting the step to read the URL from a field should fix one of the check() errors
meta.setUrlInField(true);
meta.setUrlField("urlField");
prev.addValueMeta(new ValueMetaString("urlField"));
remarks.clear();
meta.check(remarks, transMeta, step, prev, input, output, info, variables, repo, metaStore);
int errorsCurrent = getCheckResultErrorCount(remarks);
assertTrue(errorsDefault > errorsCurrent);
}
use of org.pentaho.di.core.variables.VariableSpace in project pentaho-kettle by pentaho.
the class LdapProtocolFactoryTest method createLdapProtocol.
@Test
public void createLdapProtocol() throws Exception {
String ldapVariable = "${ldap_protocol_variable}";
String ldap = "LDAP";
String host = "localhost";
LdapProtocolFactory ldapProtocolFactory = new LdapProtocolFactory(Mockito.mock(LogChannelInterface.class));
VariableSpace variableSpace = Mockito.mock(VariableSpace.class);
LdapMeta meta = Mockito.mock(LdapMeta.class);
Mockito.doReturn(ldapVariable).when(meta).getProtocol();
Mockito.doReturn(ldap).when(variableSpace).environmentSubstitute(ldapVariable);
Mockito.doReturn(host).when(meta).getHost();
Mockito.doReturn(host).when(variableSpace).environmentSubstitute(host);
ldapProtocolFactory.createLdapProtocol(variableSpace, meta, Collections.emptyList());
Mockito.verify(variableSpace, Mockito.times(1)).environmentSubstitute(ldapVariable);
}
use of org.pentaho.di.core.variables.VariableSpace 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.VariableSpace 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.VariableSpace in project pentaho-kettle by pentaho.
the class GetRepositoryNamesTest method init.
private void init(Repository repository, String directoryName, boolean includeSubFolders, String nameMask, String exludeNameMask, ObjectTypeSelection typeSelection, int itemCount) throws KettleException {
VariableSpace vars = new Variables();
vars.setVariable("DirName", "/subdir1");
vars.setVariable("IncludeMask", ".*");
vars.setVariable("ExcludeMask", "");
GetRepositoryNamesMeta meta = new GetRepositoryNamesMeta();
meta.setDirectory(new String[] { directoryName });
meta.setNameMask(new String[] { nameMask });
meta.setExcludeNameMask(new String[] { exludeNameMask });
meta.setIncludeSubFolders(new boolean[] { includeSubFolders });
meta.setObjectTypeSelection(typeSelection);
StepMeta stepMeta = new StepMeta("GetRepoNamesStep", meta);
TransMeta transMeta = new TransMeta(vars);
transMeta.setRepository(repository);
transMeta.addStep(stepMeta);
GetRepositoryNamesData data = (GetRepositoryNamesData) meta.getStepData();
GetRepositoryNames step = new GetRepositoryNames(stepMeta, data, 0, transMeta, new Trans(transMeta));
step.init(meta, data);
assertNotNull(data.list);
assertEquals(itemCount, data.list.size());
}
Aggregations