Search in sources :

Example 96 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class ScriptValuesModTest method variableIsSetInScopeOfStep.

@Test
public void variableIsSetInScopeOfStep() throws Exception {
    ScriptValuesMod step = StepMockUtil.getStep(ScriptValuesMod.class, ScriptValuesMetaMod.class, "test");
    RowMeta input = new RowMeta();
    input.addValueMeta(new ValueMetaString("str"));
    step.setInputRowMeta(input);
    step = spy(step);
    doReturn(new Object[] { "" }).when(step).getRow();
    ScriptValuesMetaMod meta = new ScriptValuesMetaMod();
    meta.setCompatible(false);
    meta.allocate(1);
    meta.setFieldname(new String[] { "str" });
    meta.setType(new int[] { ValueMetaInterface.TYPE_STRING });
    meta.setReplace(new boolean[] { true });
    meta.setJSScripts(new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "setVariable('temp', 'pass', 'r');\nstr = getVariable('temp', 'fail');") });
    ScriptValuesModData data = new ScriptValuesModData();
    step.init(meta, data);
    Object[] expectedRow = { "pass" };
    Object[] row = TransTestingUtil.execute(step, meta, data, 1, false).get(0);
    TransTestingUtil.assertResult(expectedRow, row);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) Test(org.junit.Test)

Example 97 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class StreamLookupTest method mockDataRowSet.

private RowSet mockDataRowSet(boolean binary) {
    final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL;
    Object[][] data = { { "Name1", "1" }, { "Name2", "2" } };
    if (binary) {
        convertDataToBinary(data);
    }
    RowSet dataRowSet = smh.getMockInputRowSet(data);
    RowMeta dataRowMeta = new RowMeta();
    ValueMetaString valueMeta = new ValueMetaString("Name");
    valueMeta.setStorageType(storageType);
    valueMeta.setStorageMetadata(new ValueMetaString());
    dataRowMeta.addValueMeta(valueMeta);
    ValueMetaString idMeta = new ValueMetaString("Id");
    idMeta.setStorageType(storageType);
    idMeta.setStorageMetadata(new ValueMetaString());
    dataRowMeta.addValueMeta(idMeta);
    doReturn(dataRowMeta).when(dataRowSet).getRowMeta();
    return dataRowSet;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet)

Example 98 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class StreamLookupTest method mockLookupRowSet.

private RowSet mockLookupRowSet(boolean binary) {
    final int storageType = binary ? ValueMetaInterface.STORAGE_TYPE_BINARY_STRING : ValueMetaInterface.STORAGE_TYPE_NORMAL;
    Object[][] data = { { "Value1", "1" }, { "Value2", "2" } };
    if (binary) {
        convertDataToBinary(data);
    }
    RowSet lookupRowSet = smh.getMockInputRowSet(data);
    doReturn("Lookup").when(lookupRowSet).getOriginStepName();
    doReturn("StreamLookup").when(lookupRowSet).getDestinationStepName();
    RowMeta lookupRowMeta = new RowMeta();
    ValueMetaString valueMeta = new ValueMetaString("Value");
    valueMeta.setStorageType(storageType);
    valueMeta.setStorageMetadata(new ValueMetaString());
    lookupRowMeta.addValueMeta(valueMeta);
    ValueMetaString idMeta = new ValueMetaString("Id");
    idMeta.setStorageType(storageType);
    idMeta.setStorageMetadata(new ValueMetaString());
    lookupRowMeta.addValueMeta(idMeta);
    doReturn(lookupRowMeta).when(lookupRowSet).getRowMeta();
    return lookupRowSet;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet)

Example 99 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class TableInputMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    TableInputMetaHandler meta = new TableInputMetaHandler();
    meta.setLazyConversionActive(true);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    meta.setDatabaseMeta(dbMeta);
    Database mockDB = meta.getDatabase();
    when(mockDB.getQueryFields(anyString(), anyBoolean())).thenReturn(createMockFields());
    RowMetaInterface expectedRowMeta = new RowMeta();
    ValueMetaInterface valueMeta = new ValueMetaString("field1");
    valueMeta.setStorageMetadata(new ValueMetaString("field1"));
    valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    expectedRowMeta.addValueMeta(valueMeta);
    VariableSpace space = mock(VariableSpace.class);
    RowMetaInterface rowMetaInterface = new RowMeta();
    meta.getFields(rowMetaInterface, "TABLE_INPUT_META", null, null, space, null, null);
    assertEquals(expectedRowMeta.toString(), rowMetaInterface.toString());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 100 with ValueMetaString

use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.

the class TextFileInputTest method readWrappedInputWithoutHeaders.

@Test
public void readWrappedInputWithoutHeaders() throws Exception {
    final String content = new StringBuilder().append("r1c1").append('\n').append(";r1c2\n").append("r2c1").append('\n').append(";r2c2").toString();
    final String virtualFile = createVirtualFile("pdi-2607.txt", content);
    TextFileInputMeta meta = new TextFileInputMeta();
    meta.setLineWrapped(true);
    meta.setNrWraps(1);
    meta.setInputFields(new TextFileInputField[] { field("col1"), field("col2") });
    meta.setFileCompression("None");
    meta.setFileType("CSV");
    meta.setHeader(false);
    meta.setNrHeaderLines(-1);
    meta.setFooter(false);
    meta.setNrFooterLines(-1);
    TextFileInputData data = new TextFileInputData();
    data.setFiles(new FileInputList());
    data.getFiles().addFile(KettleVFS.getFileObject(virtualFile));
    data.outputRowMeta = new RowMeta();
    data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
    data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
    data.dataErrorLineHandler = Mockito.mock(FileErrorHandler.class);
    data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
    data.separator = ";";
    data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
    data.filePlayList = new FilePlayListAll();
    TextFileInput input = StepMockUtil.getStep(TextFileInput.class, TextFileInputMeta.class, "test");
    List<Object[]> output = TransTestingUtil.execute(input, meta, data, 2, false);
    TransTestingUtil.assertResult(new Object[] { "r1c1", "r1c2" }, output.get(0));
    TransTestingUtil.assertResult(new Object[] { "r2c1", "r2c2" }, output.get(1));
    deleteVfsFile(virtualFile);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) FilePlayListAll(org.pentaho.di.core.playlist.FilePlayListAll) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileErrorHandler(org.pentaho.di.trans.step.errorhandling.FileErrorHandler) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Test(org.junit.Test)

Aggregations

ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)447 RowMeta (org.pentaho.di.core.row.RowMeta)219 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)181 Test (org.junit.Test)179 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)176 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)141 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)86 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)67 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)66 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)57 KettleException (org.pentaho.di.core.exception.KettleException)40 ArrayList (java.util.ArrayList)33 LongObjectId (org.pentaho.di.repository.LongObjectId)29 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)27 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)26 ObjectId (org.pentaho.di.repository.ObjectId)26 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 RowSet (org.pentaho.di.core.RowSet)18 Date (java.util.Date)17 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)16