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