Search in sources :

Example 1 with BulkResult

use of org.talend.components.salesforce.runtime.BulkResult 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 BulkResult

use of org.talend.components.salesforce.runtime.BulkResult in project components by Talend.

the class BulkResultTest method testCopyValues.

@Test
public void testCopyValues() throws IOException {
    BulkResult result = new BulkResult();
    result.setValue("fieldA", "fieldValueA");
    result.setValue("fieldB", "fieldValueB");
    result.setValue("fieldC", "fieldValueC");
    result.setValue("fieldD", "#N/A");
    BulkResult result2 = new BulkResult();
    result2.copyValues(result);
    assertEquals("fieldValueA", result2.getValue("fieldA"));
    assertEquals("fieldValueB", result2.getValue("fieldB"));
    assertEquals("fieldValueC", result2.getValue("fieldC"));
    assertNull(result2.getValue("fieldD"));
    BulkResult result3 = new BulkResult();
    result3.copyValues(null);
    assertNull(result3.getValue("fieldA"));
    assertNull(result3.getValue("fieldB"));
}
Also used : BulkResult(org.talend.components.salesforce.runtime.BulkResult) Test(org.junit.Test)

Example 3 with BulkResult

use of org.talend.components.salesforce.runtime.BulkResult 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)

Example 4 with BulkResult

use of org.talend.components.salesforce.runtime.BulkResult in project components by Talend.

the class BulkResultIndexedRecordConverterTest method testIndexedRecordUnmodifiable.

@Test(expected = IndexedRecordConverter.UnmodifiableAdapterException.class)
public void testIndexedRecordUnmodifiable() throws IOException {
    converter.setSchema(SCHEMA);
    BulkResult result = new BulkResult();
    result.setValue("Id", "12345");
    result.setValue("Name", "Qwerty");
    result.setValue("FieldX", "42");
    result.setValue("FieldY", "true");
    IndexedRecord indexedRecord = converter.convertToAvro(result);
    indexedRecord.put(1, "Asdfgh");
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) BulkResult(org.talend.components.salesforce.runtime.BulkResult) Test(org.junit.Test)

Example 5 with BulkResult

use of org.talend.components.salesforce.runtime.BulkResult in project components by Talend.

the class BulkResultIndexedRecordConverterTest method testConvertToAvro.

@Test
public void testConvertToAvro() throws IOException {
    converter.setSchema(SCHEMA);
    assertNotNull(converter.getSchema());
    assertEquals(BulkResult.class, converter.getDatumClass());
    BulkResult result = new BulkResult();
    result.setValue("Id", "12345");
    result.setValue("Name", "Qwerty");
    result.setValue("FieldX", "42");
    result.setValue("FieldY", "true");
    IndexedRecord indexedRecord = converter.convertToAvro(result);
    assertNotNull(indexedRecord);
    assertNotNull(indexedRecord.getSchema());
    assertEquals(SCHEMA, indexedRecord.getSchema());
    assertEquals("12345", indexedRecord.get(0));
    assertEquals("Qwerty", indexedRecord.get(1));
    assertEquals("42", indexedRecord.get(2));
    assertEquals("true", indexedRecord.get(3));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) BulkResult(org.talend.components.salesforce.runtime.BulkResult) Test(org.junit.Test)

Aggregations

BulkResult (org.talend.components.salesforce.runtime.BulkResult)7 Test (org.junit.Test)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 CsvReader (com.csvreader.CsvReader)2 CsvWriter (com.csvreader.CsvWriter)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BulkResultSet (org.talend.components.salesforce.runtime.BulkResultSet)2