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);
}
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;
}
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;
}
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());
}
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);
}
Aggregations