Search in sources :

Example 71 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class DatabaseMeta_AppendExtraParamsTest method setUp.

@Before
public void setUp() throws KettleDatabaseException {
    meta = mock(DatabaseMeta.class);
    mssqlServerDatabaseMeta = new MSSQLServerDatabaseMeta();
    variables = new Variables();
    mssqlServerDatabaseMeta.setPluginId(CONN_TYPE_MSSQL);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return variables.environmentSubstitute((String) invocation.getArguments()[0]);
        }
    }).when(meta).environmentSubstitute(anyString());
    doReturn(mssqlServerDatabaseMeta).when(meta).getDatabaseInterface();
    doCallRealMethod().when(meta).appendExtraOptions(anyString(), anyMapOf(String.class, String.class));
    doCallRealMethod().when(meta).databaseForBothDbInterfacesIsTheSame(any(DatabaseInterface.class), any(DatabaseInterface.class));
    doCallRealMethod().when(meta).getExtraOptionIndicator();
    doCallRealMethod().when(meta).getExtraOptionSeparator();
    doCallRealMethod().when(meta).getExtraOptionValueSeparator();
    doReturn(mock(LogChannelInterface.class)).when(meta).getGeneralLogger();
    doReturn(mssqlServerDatabaseMeta).when(meta).getDbInterface(CONN_TYPE_MSSQL);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Before(org.junit.Before)

Example 72 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class HttpUtilTest method testConstructUrl.

@Test
public void testConstructUrl() throws Exception {
    Variables variables = new Variables();
    String expected = "hostname:1234/webAppName?param=value";
    Assert.assertEquals("http://" + expected, HttpUtil.constructUrl(variables, "hostname", String.valueOf(1234), "webAppName", "?param=value"));
    Assert.assertEquals("http://" + expected, HttpUtil.constructUrl(variables, "hostname", String.valueOf(1234), "webAppName", "?param=value", false));
    Assert.assertEquals("https://" + expected, HttpUtil.constructUrl(variables, "hostname", String.valueOf(1234), "webAppName", "?param=value", true));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Test(org.junit.Test)

Example 73 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class StepWithMappingMetaTest method loadMappingMetaTest.

@Test
@PrepareForTest(StepWithMappingMeta.class)
public void loadMappingMetaTest() throws Exception {
    String childParam = "childParam";
    String childValue = "childValue";
    String paramOverwrite = "paramOverwrite";
    String parentParam = "parentParam";
    String parentValue = "parentValue";
    String variablePath = "Internal.Entry.Current.Directory";
    String virtualDir = "/testFolder/CDA-91";
    String fileName = "testTrans.ktr";
    VariableSpace variables = new Variables();
    variables.setVariable(parentParam, parentValue);
    variables.setVariable(paramOverwrite, parentValue);
    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);
    Repository rep = mock(Repository.class);
    Mockito.doReturn(Mockito.mock(RepositoryDirectoryInterface.class)).when(rep).findDirectory(anyString());
    TransMeta child = new TransMeta();
    child.setVariable(childParam, childValue);
    child.setVariable(paramOverwrite, childValue);
    Mockito.doReturn(child).when(rep).loadTransformation(anyString(), any(), any(), anyBoolean(), any());
    TransMeta transMeta = StepWithMappingMeta.loadMappingMeta(mappingMetaMock, rep, null, variables, true);
    Assert.assertNotNull(transMeta);
    // When the child parameter does exist in the parent parameters, overwrite the child parameter by the parent parameter.
    Assert.assertEquals(parentValue, transMeta.getVariable(paramOverwrite));
    // When the child parameter does not exist in the parent parameters, keep it.
    Assert.assertEquals(childValue, transMeta.getVariable(childParam));
    // All other parent parameters need to get copied into the child parameters  (when the 'Inherit all
    // variables from the transformation?' option is checked)
    Assert.assertEquals(parentValue, transMeta.getVariable(parentParam));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Mockito.anyString(org.mockito.Mockito.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 74 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class SubtransExecutorTest method testRunsATrans.

@Test
public void testRunsATrans() throws Exception {
    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 = spy(new Trans(parentMeta, loggingObject));
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "Group By");
    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));
    Optional<Result> optionalResult = subtransExecutor.execute(rows);
    assertEquals(1, optionalResult.orElseThrow(AssertionError::new).getRows().size());
    verify(this.logChannel).logBasic(Const.CR + "------------> Linenr 1------------------------------" + Const.CR + "name = Pentaho" + Const.CR + "sum = 10" + Const.CR + Const.CR + "====================");
    Map<String, StepStatus> statuses = subtransExecutor.getStatuses();
    assertEquals(3, statuses.size());
    List<StepStatus> statusList = new ArrayList<>(statuses.values());
    assertEquals("Get rows from result", statusList.get(0).getStepname());
    assertEquals("Group by", statusList.get(1).getStepname());
    assertEquals("Write to log", statusList.get(2).getStepname());
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        StepStatus statusSpy = spy(entry.getValue());
        statuses.put(entry.getKey(), statusSpy);
    }
    subtransExecutor.execute(rows);
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        verify(entry.getValue()).updateAll(any());
    }
    verify(parentTrans, atLeastOnce()).addActiveSubTransformation(eq("subtransname"), any(Trans.class));
}
Also used : ArrayList(java.util.ArrayList) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepStatus(org.pentaho.di.trans.step.StepStatus) Result(org.pentaho.di.core.Result) Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Map(java.util.Map) Test(org.junit.Test)

Example 75 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class SubtransExecutorTest method doesNotExecuteWhenStopped.

@Test
public void doesNotExecuteWhenStopped() 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(), "");
    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.stop();
    subtransExecutor.execute(rows);
    verify(this.logChannel, never()).logBasic("\n" + "------------> Linenr 1------------------------------\n" + "name = Pentaho\n" + "sum = 10\n" + "\n" + "====================");
}
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)

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