use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.
the class TextFileInputTest method readInputWithDefaultValues.
@Test
public void readInputWithDefaultValues() throws Exception {
final String virtualFile = createVirtualFile("pdi-14832.txt", "1,\n");
TextFileInputMeta meta = new TextFileInputMeta();
TextFileInputField field2 = field("col2");
field2.setIfNullValue("DEFAULT");
meta.setInputFields(new TextFileInputField[] { field("col1"), field2 });
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(HopVfs.getFileObject(virtualFile));
data.outputRowMeta = new RowMeta();
data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
data.dataErrorLineHandler = Mockito.mock(IFileErrorHandler.class);
data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
data.separator = ",";
data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
data.filePlayList = new FilePlayListAll();
TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
List<Object[]> output = PipelineTestingUtil.execute(input, 1, false);
PipelineTestingUtil.assertResult(new Object[] { "1", "DEFAULT" }, output.get(0));
deleteVfsFile(virtualFile);
}
use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.
the class TextFileInputTest method readInputWithMissedValues.
@Test
public void readInputWithMissedValues() throws Exception {
final String virtualFile = createVirtualFile("pdi-14172.txt", "1,1,1\n", "2,,2\n");
TextFileInputMeta meta = new TextFileInputMeta();
TextFileInputField field2 = field("col2");
field2.setRepeated(true);
meta.setInputFields(new TextFileInputField[] { field("col1"), field2, field("col3") });
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(HopVfs.getFileObject(virtualFile));
data.outputRowMeta = new RowMeta();
data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
data.outputRowMeta.addValueMeta(new ValueMetaString("col3"));
data.dataErrorLineHandler = Mockito.mock(IFileErrorHandler.class);
data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
data.separator = ",";
data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
data.filePlayList = new FilePlayListAll();
TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
List<Object[]> output = PipelineTestingUtil.execute(input, 2, false);
PipelineTestingUtil.assertResult(new Object[] { "1", "1", "1" }, output.get(0));
PipelineTestingUtil.assertResult(new Object[] { "2", "1", "2" }, output.get(1));
deleteVfsFile(virtualFile);
}
use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.
the class TextFileInputTest method createDataObject.
private TextFileInputData createDataObject(String file, String separator, String... outputFields) throws Exception {
TextFileInputData data = new TextFileInputData();
data.files = new FileInputList();
data.files.addFile(HopVfs.getFileObject(file));
data.separator = separator;
data.outputRowMeta = new RowMeta();
if (outputFields != null) {
for (String field : outputFields) {
data.outputRowMeta.addValueMeta(new ValueMetaString(field));
}
}
data.dataErrorLineHandler = mock(IFileErrorHandler.class);
data.fileFormatType = TextFileLineUtil.FILE_FORMAT_UNIX;
data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0], new Variables());
data.filePlayList = new FilePlayListAll();
return data;
}
use of org.apache.hop.core.playlist.FilePlayListAll in project hop by apache.
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(HopVfs.getFileObject(virtualFile));
data.outputRowMeta = new RowMeta();
data.outputRowMeta.addValueMeta(new ValueMetaString("col1"));
data.outputRowMeta.addValueMeta(new ValueMetaString("col2"));
data.dataErrorLineHandler = Mockito.mock(IFileErrorHandler.class);
data.fileFormatType = TextFileInputMeta.FILE_FORMAT_UNIX;
data.separator = ";";
data.filterProcessor = new TextFileFilterProcessor(new TextFileFilter[0]);
data.filePlayList = new FilePlayListAll();
TextFileInput input = TransformMockUtil.getTransform(TextFileInput.class, meta, data, TextFileInputMeta.class, TextFileInputData.class, "test");
List<Object[]> output = PipelineTestingUtil.execute(input, 2, false);
PipelineTestingUtil.assertResult(new Object[] { "r1c1", "r1c2" }, output.get(0));
PipelineTestingUtil.assertResult(new Object[] { "r2c1", "r2c2" }, output.get(1));
deleteVfsFile(virtualFile);
}
Aggregations