Search in sources :

Example 6 with Variables

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

the class XMLOutputMetaTest method testExportResources.

@Test
public void testExportResources() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    ResourceNamingInterface resourceNamingInterface = mock(ResourceNamingInterface.class);
    Variables space = new Variables();
    when(resourceNamingInterface.nameResource(any(FileObject.class), eq(space), eq(true))).thenReturn("exportFile");
    xmlOutputMeta.exportResources(space, null, resourceNamingInterface, null, null);
    assertEquals("exportFile", xmlOutputMeta.getFileName());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) FileObject(org.apache.commons.vfs2.FileObject) ResourceNamingInterface(org.pentaho.di.resource.ResourceNamingInterface) Test(org.junit.Test)

Example 7 with Variables

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

the class XMLOutputMetaTest method testCheck.

@Test
public void testCheck() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    TransMeta transMeta = mock(TransMeta.class);
    StepMeta stepInfo = mock(StepMeta.class);
    RowMetaInterface prev = mock(RowMetaInterface.class);
    Repository repos = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    RowMetaInterface info = mock(RowMetaInterface.class);
    ArrayList<CheckResultInterface> remarks = new ArrayList<>();
    xmlOutputMeta.check(remarks, transMeta, stepInfo, prev, new String[] { "input" }, new String[] { "output" }, info, new Variables(), repos, metastore);
    assertEquals(2, remarks.size());
    assertEquals("Step is receiving info from other steps.", remarks.get(0).getText());
    assertEquals("File specifications are not checked.", remarks.get(1).getText());
    XMLField xmlField = new XMLField();
    xmlField.setFieldName("aField");
    xmlField.setType(1);
    xmlField.setLength(10);
    xmlField.setPrecision(3);
    xmlOutputMeta.setOutputFields(new XMLField[] { xmlField });
    when(prev.size()).thenReturn(1);
    remarks.clear();
    xmlOutputMeta.check(remarks, transMeta, stepInfo, prev, new String[] { "input" }, new String[] { "output" }, info, new Variables(), repos, metastore);
    assertEquals(4, remarks.size());
    assertEquals("Step is connected to previous one, receiving 1 fields", remarks.get(0).getText());
    assertEquals("All output fields are found in the input stream.", remarks.get(1).getText());
    assertEquals("Step is receiving info from other steps.", remarks.get(2).getText());
    assertEquals("File specifications are not checked.", remarks.get(3).getText());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 8 with Variables

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

the class XMLOutputMetaTest method testGetFiles.

@Test
public void testGetFiles() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    xmlOutputMeta.setStepNrInFilename(true);
    xmlOutputMeta.setSplitEvery(100);
    xmlOutputMeta.setSpecifyFormat(true);
    xmlOutputMeta.setDateTimeFormat("99");
    String[] files = xmlOutputMeta.getFiles(new Variables());
    assertEquals(10, files.length);
    assertArrayEquals(new String[] { "file99_0_00001.xml", "file99_0_00002.xml", "file99_0_00003.xml", "file99_1_00001.xml", "file99_1_00002.xml", "file99_1_00003.xml", "file99_2_00001.xml", "file99_2_00002.xml", "file99_2_00003.xml", "..." }, files);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Test(org.junit.Test)

Example 9 with Variables

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

the class XMLOutputMetaTest method testGetRequiredFields.

@Test
public void testGetRequiredFields() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    XMLField xmlField = new XMLField();
    xmlField.setFieldName("aField");
    xmlField.setType(1);
    xmlField.setLength(10);
    xmlField.setPrecision(3);
    XMLField xmlField2 = new XMLField();
    xmlField2.setFieldName("bField");
    xmlField2.setType(3);
    xmlField2.setLength(4);
    xmlField2.setPrecision(5);
    xmlOutputMeta.setOutputFields(new XMLField[] { xmlField, xmlField2 });
    RowMetaInterface requiredFields = xmlOutputMeta.getRequiredFields(new Variables());
    List<ValueMetaInterface> valueMetaList = requiredFields.getValueMetaList();
    assertEquals(2, valueMetaList.size());
    assertEquals("aField", valueMetaList.get(0).getName());
    assertEquals(1, valueMetaList.get(0).getType());
    assertEquals(10, valueMetaList.get(0).getLength());
    assertEquals(3, valueMetaList.get(0).getPrecision());
    assertEquals("bField", valueMetaList.get(1).getName());
    assertEquals(3, valueMetaList.get(1).getType());
    assertEquals(4, valueMetaList.get(1).getLength());
    assertEquals(5, valueMetaList.get(1).getPrecision());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 10 with Variables

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

the class EditRowsDialog method addFields.

private boolean addFields() {
    // int middle = props.getMiddlePct();
    int margin = Const.MARGIN;
    if (wlMessage == null) {
        wlMessage = new Label(shell, SWT.LEFT);
        wlMessage.setText(message);
        props.setLook(wlMessage);
        fdlFields = new FormData();
        fdlFields.left = new FormAttachment(0, 0);
        fdlFields.right = new FormAttachment(100, 0);
        fdlFields.top = new FormAttachment(0, margin);
        wlMessage.setLayoutData(fdlFields);
    } else {
        wFields.dispose();
    }
    // Mmm, if we don't get any row metadata: show a dialog box.
    if (rowMeta == null || rowMeta.size() == 0) {
        ShowMessageDialog dialog = new ShowMessageDialog(shell, SWT.OK | SWT.ICON_WARNING, BaseMessages.getString(PKG, "EditRowsDialog.NoRowMeta.Text"), BaseMessages.getString(PKG, "EditRowsDialog.NoRowMeta.Message"));
        dialog.open();
        shell.dispose();
        return true;
    }
    // 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, rowBuffer.size(), null, props);
    wFields.setShowingBlueNullValues(true);
    fdFields = new FormData();
    fdFields.left = new FormAttachment(0, 0);
    fdFields.top = new FormAttachment(wlMessage, margin);
    fdFields.right = new FormAttachment(100, 0);
    fdFields.bottom = new FormAttachment(100, -50);
    wFields.setLayoutData(fdFields);
    shell.layout(true, true);
    return false;
}
Also used : FormData(org.eclipse.swt.layout.FormData) Variables(org.pentaho.di.core.variables.Variables) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) FormAttachment(org.eclipse.swt.layout.FormAttachment) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) TableView(org.pentaho.di.ui.core.widget.TableView)

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