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);
}
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));
}
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));
}
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));
}
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" + "====================");
}
Aggregations