Search in sources :

Example 11 with VariableSpace

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);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) Test(org.junit.Test)

Example 12 with VariableSpace

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);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 13 with VariableSpace

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));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Mockito.anyString(org.mockito.Mockito.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with VariableSpace

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);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Mockito.anyString(org.mockito.Mockito.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProgressMonitorListener(org.pentaho.di.core.ProgressMonitorListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with VariableSpace

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());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

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