Search in sources :

Example 1 with BulkResultSet

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);
}
Also used : CsvReader(com.csvreader.CsvReader) BulkResultSet(org.talend.components.salesforce.runtime.BulkResultSet) CsvWriter(com.csvreader.CsvWriter) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BulkResult(org.talend.components.salesforce.runtime.BulkResult) Test(org.junit.Test)

Example 2 with BulkResultSet

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) {
    }
}
Also used : CsvReader(com.csvreader.CsvReader) BulkResultSet(org.talend.components.salesforce.runtime.BulkResultSet) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with BulkResultSet

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();
}
Also used : CsvReader(com.csvreader.CsvReader) BulkResultSet(org.talend.components.salesforce.runtime.BulkResultSet) CsvWriter(com.csvreader.CsvWriter) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BulkResult(org.talend.components.salesforce.runtime.BulkResult)

Aggregations

CsvReader (com.csvreader.CsvReader)3 BufferedInputStream (java.io.BufferedInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BulkResultSet (org.talend.components.salesforce.runtime.BulkResultSet)3 CsvWriter (com.csvreader.CsvWriter)2 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 BulkResult (org.talend.components.salesforce.runtime.BulkResult)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1