use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class BaseStreamStepMetaTest method testCheckErrorsOnVariablesSubstituteError.
@Test
public void testCheckErrorsOnVariablesSubstituteError() {
List<CheckResultInterface> remarks = new ArrayList<>();
Variables space = new Variables();
space.setVariable("something", "0");
meta.setBatchSize("${something}");
meta.setBatchDuration("${something}");
meta.check(remarks, null, null, null, null, null, null, space, null, null);
assertEquals(1, remarks.size());
assertEquals("The \"Number of records\" and \"Duration\" fields can’t both be set to 0. Please set a value of 1 " + "or higher for one of the fields.", remarks.get(0).getText());
testRoundTrip(meta);
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class JobExecutorMetaTest method testLoadJobMeta.
@Test
public void testLoadJobMeta() throws KettleException {
String param1 = "param1";
String param2 = "param2";
String param3 = "param3";
String parentValue1 = "parentValue1";
String parentValue2 = "parentValue2";
String childValue3 = "childValue3";
JobExecutorMeta jobExecutorMeta = spy(new JobExecutorMeta());
Repository repository = Mockito.mock(Repository.class);
JobMeta meta = new JobMeta();
meta.setVariable(param2, "childValue2 should be override");
meta.setVariable(param3, childValue3);
Mockito.doReturn(meta).when(repository).loadJob(Mockito.eq("test.kjb"), Mockito.anyObject(), Mockito.anyObject(), Mockito.anyObject());
VariableSpace parentSpace = new Variables();
parentSpace.setVariable(param1, parentValue1);
parentSpace.setVariable(param2, parentValue2);
jobExecutorMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
jobExecutorMeta.setFileName("/home/admin/test.kjb");
JobMeta jobMeta;
jobExecutorMeta.getParameters().setInheritingAllVariables(false);
jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
Assert.assertEquals(null, jobMeta.getVariable(param1));
Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
jobExecutorMeta.getParameters().setInheritingAllVariables(true);
jobMeta = JobExecutorMeta.loadJobMeta(jobExecutorMeta, repository, parentSpace);
Assert.assertEquals(parentValue1, jobMeta.getVariable(param1));
Assert.assertEquals(parentValue2, jobMeta.getVariable(param2));
Assert.assertEquals(childValue3, jobMeta.getVariable(param3));
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class Translator2 method addLists.
private void addLists() {
Composite composite = new Composite(sashform, SWT.NONE);
props.setLook(composite);
FormLayout formLayout = new FormLayout();
formLayout.marginHeight = Const.FORM_MARGIN;
formLayout.marginWidth = Const.FORM_MARGIN;
composite.setLayout(formLayout);
wLocale = new List(composite, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
FormData fdLocale = new FormData();
fdLocale.left = new FormAttachment(0, 0);
fdLocale.right = new FormAttachment(100, 0);
fdLocale.top = new FormAttachment(0, 0);
fdLocale.bottom = new FormAttachment(10, 0);
wLocale.setLayoutData(fdLocale);
ColumnInfo[] colinfo = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "i18nDialog.SourceFolder"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "i18nDialog.Packagename"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
wPackages = new TableView(new Variables(), composite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER, colinfo, 1, true, null, props);
FormData fdPackages = new FormData();
fdPackages.left = new FormAttachment(0, 0);
fdPackages.right = new FormAttachment(100, 0);
fdPackages.top = new FormAttachment(wLocale, Const.MARGIN);
fdPackages.bottom = new FormAttachment(100, 0);
wPackages.setLayoutData(fdPackages);
wPackages.setSortable(false);
FormData fdComposite = new FormData();
fdComposite.left = new FormAttachment(0, 0);
fdComposite.right = new FormAttachment(100, 0);
fdComposite.top = new FormAttachment(0, 0);
fdComposite.bottom = new FormAttachment(100, 0);
composite.setLayoutData(fdComposite);
// Add a selection listener.
wLocale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
refreshGrid();
}
});
wPackages.table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
refreshGrid();
}
});
composite.layout();
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class SubjectDataBrowserDialog method addFields.
private boolean addFields() {
// int middle = props.getMiddlePct();
int margin = Const.MARGIN;
if (wlSubjectMessage == null) {
wlSubjectMessage = new Label(shell, SWT.LEFT);
wlSubjectMessage.setText(subjectMessage);
props.setLook(wlSubjectMessage);
FormData fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(0, margin);
wlSubjectMessage.setLayoutData(fdlFields);
wSubject = new CCombo(shell, SWT.LEFT | SWT.READ_ONLY | SWT.BORDER);
wSubject.setItems(subjects);
wSubject.setText(selectedSubject);
props.setLook(wSubject);
FormData fdlSubject = new FormData();
fdlSubject.left = new FormAttachment(wlSubjectMessage, margin);
// fdlSubject.right = new FormAttachment(100, 0);
fdlSubject.top = new FormAttachment(wlSubjectMessage, 0, SWT.CENTER);
wSubject.setLayoutData(fdlSubject);
wSubject.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
selectedSubject = wSubject.getText();
// Refresh
addFields();
}
});
} else {
wFields.dispose();
}
RowMetaInterface rowMeta = metaMap.get(selectedSubject);
List<Object[]> buffer = dataMap.get(selectedSubject);
//
if (buffer == null) {
buffer = new ArrayList<Object[]>();
}
// ColumnInfo[] colinf = new ColumnInfo[rowMeta==null ? 0 : rowMeta.size()];
ColumnInfo[] colinf = new ColumnInfo[rowMeta.size()];
for (int i = 0; i < rowMeta.size(); i++) {
ValueMetaInterface v = rowMeta.getValueMeta(i);
colinf[i] = new ColumnInfo(v.getName(), ColumnInfo.COLUMN_TYPE_TEXT, v.isNumeric());
colinf[i].setToolTip(v.toStringMeta());
colinf[i].setValueMeta(v);
}
wFields = new TableView(new Variables(), shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, 0, null, props);
wFields.setShowingBlueNullValues(true);
FormData fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wSubject, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, -50);
wFields.setLayoutData(fdFields);
//
for (int i = 0; i < buffer.size(); i++) {
TableItem item;
if (i == 0) {
item = wFields.table.getItem(i);
} else {
item = new TableItem(wFields.table, SWT.NONE);
}
Object[] rowData = buffer.get(i);
getDataForRow(item, rowMeta, rowData, i + 1);
}
if (!wFields.isDisposed()) {
wFields.optWidth(true, 200);
}
shell.layout(true, true);
return false;
}
use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.
the class XMLOutputMetaTest method testGetFields.
@Test
public void testGetFields() throws Exception {
XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
xmlOutputMeta.setDefault();
XMLField xmlField = new XMLField();
xmlField.setFieldName("aField");
xmlField.setLength(10);
xmlField.setPrecision(3);
xmlOutputMeta.setOutputFields(new XMLField[] { xmlField });
RowMetaInterface row = mock(RowMetaInterface.class);
RowMetaInterface rmi = mock(RowMetaInterface.class);
StepMeta nextStep = mock(StepMeta.class);
Repository repo = mock(Repository.class);
IMetaStore metastore = mock(IMetaStore.class);
ValueMetaInterface vmi = mock(ValueMetaInterface.class);
when(row.searchValueMeta("aField")).thenReturn(vmi);
xmlOutputMeta.getFields(row, "", new RowMetaInterface[] { rmi }, nextStep, new Variables(), repo, metastore);
verify(vmi).setLength(10, 3);
}
Aggregations