Search in sources :

Example 36 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) RowMeta(org.pentaho.di.core.row.RowMeta) FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 37 with Variables

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));
}
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 38 with Variables

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);
}
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 39 with Variables

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());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Test(org.junit.Test)

Example 40 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7