use of org.talend.components.salesforce.runtime.BulkResultSet in project components by Talend.
the class BulkResultSetTest method testResultSet.
@Test
public void testResultSet() throws IOException {
final int recordCount = 100;
ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter csvWriter = new CsvWriter(new BufferedOutputStream(out), ',', Charset.forName("UTF-8"));
for (int i = 0; i < recordCount; i++) {
csvWriter.writeRecord(new String[] { "fieldValueA" + i, "fieldValueB" + i, "fieldValueC" + i });
}
csvWriter.close();
CsvReader csvReader = new CsvReader(new BufferedInputStream(new ByteArrayInputStream(out.toByteArray())), ',', Charset.forName("UTF-8"));
BulkResultSet resultSet = new BulkResultSet(csvReader, Arrays.asList("fieldA", "fieldB", "fieldC"));
int count = 0;
BulkResult result;
while ((result = resultSet.next()) != null) {
assertEquals("fieldValueA" + count, result.getValue("fieldA"));
assertEquals("fieldValueB" + count, result.getValue("fieldB"));
assertEquals("fieldValueC" + count, result.getValue("fieldC"));
count++;
}
assertEquals(recordCount, count);
}
use of org.talend.components.salesforce.runtime.BulkResultSet in project components by Talend.
the class BulkResultSetTest method testResultSetIOError.
@Test(expected = IOException.class)
public void testResultSetIOError() throws IOException {
InputStream in = mock(InputStream.class);
doThrow(new IOException("I/O ERROR")).when(in).read();
when(in.read(any(byte[].class))).thenThrow(new IOException("I/O ERROR"));
CsvReader csvReader = new CsvReader(in, ',', Charset.forName("UTF-8"));
BulkResultSet resultSet = new BulkResultSet(csvReader, Arrays.asList("fieldA", "fieldB", "fieldC"));
while (resultSet.next() != null) {
}
}
use of org.talend.components.salesforce.runtime.BulkResultSet in project components by Talend.
the class BulkResultSetTest method prepareSafetySwitchTest.
private int prepareSafetySwitchTest(boolean safetySwitchParameter, int columnLength) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter csvWriter = new CsvWriter(new BufferedOutputStream(out), ',', Charset.forName("UTF-8"));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < columnLength; i++) {
sb.append("a");
}
String[] data = new String[] { "fieldValueA", "fieldValueB", sb.toString() };
csvWriter.writeRecord(data);
csvWriter.close();
CsvReader csvReader = new CsvReader(new BufferedInputStream(new ByteArrayInputStream(out.toByteArray())), ',', Charset.forName("UTF-8"));
csvReader.setSafetySwitch(safetySwitchParameter);
BulkResultSet resultSet = new BulkResultSet(csvReader, Arrays.asList("fieldA", "fieldB", "fieldC"));
BulkResult result = resultSet.next();
return ((String) result.getValue("fieldC")).length();
}
Aggregations