Skip to content

Commit

Permalink
Tests should use Data Loader's CSVFileReader instead of wsc FileReader
Browse files Browse the repository at this point in the history
Tests should use Data Loader's CSVFileReader instead of wsc FileReader
  • Loading branch information
ashitsalesforce committed Dec 13, 2024
1 parent 0232173 commit ea14bfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import com.salesforce.dataloader.TestVariant;
import com.salesforce.dataloader.action.OperationInfo;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.dao.csv.CSVFileReader;
import com.salesforce.dataloader.exception.DataAccessObjectException;
import com.salesforce.dataloader.exception.DataAccessObjectInitializationException;
import com.salesforce.dataloader.model.TableRow;
import com.sforce.async.CSVReader;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;
Expand Down Expand Up @@ -120,9 +124,18 @@ private Map<String, String> getBulkUnicodeExtractConfig(String soql) {
private void validateExtraction(final String name, final Map<String, String> testConfig) throws IOException {
FileInputStream fis = new FileInputStream(new File(testConfig.get(AppConfig.PROP_DAO_NAME)));
try {
CSVReader rdr = new CSVReader(fis, StandardCharsets.UTF_8.name());
int nameidx = rdr.nextRecord().indexOf("Name");
assertEquals(name, rdr.nextRecord().get(nameidx));
CSVFileReader rdr = new CSVFileReader(new File(testConfig.get(AppConfig.PROP_DAO_NAME)),
this.getController().getAppConfig(), false, true);
rdr.open();
TableRow row = rdr.readTableRow();
String extractedNameVal = (String)row.get("Name");
assertEquals(name, extractedNameVal);
} catch (DataAccessObjectInitializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DataAccessObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
IOUtils.closeQuietly(fis);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@

import com.salesforce.dataloader.action.OperationInfo;
import com.salesforce.dataloader.config.AppConfig;
import com.salesforce.dataloader.dao.csv.CSVFileReader;
import com.salesforce.dataloader.exception.DataAccessObjectException;
import com.salesforce.dataloader.exception.DataAccessObjectInitializationException;
import com.salesforce.dataloader.exception.ProcessInitializationException;
import com.salesforce.dataloader.model.TableRow;
import com.sforce.async.CSVReader;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;
Expand Down Expand Up @@ -89,14 +92,21 @@ private void runExtractionDoNotLimitOutputToQueryFields(String extractionQuery)
private void validateAccountNameInOutputFile(final String accountName, boolean isLimitOutputToQueryFields) throws IOException {
FileInputStream fis = new FileInputStream(new File(testConfig.get(AppConfig.PROP_DAO_NAME)));
try {
CSVReader rdr = new CSVReader(fis, StandardCharsets.UTF_8.name());
int acctNameIndex = 0;
CSVFileReader rdr = new CSVFileReader(new File(testConfig.get(AppConfig.PROP_DAO_NAME)),
this.getController().getAppConfig(), false, true);
rdr.open();
TableRow row = rdr.readTableRow();
String extractedNameVal = (String)row.get("Name");
if (isLimitOutputToQueryFields) {
acctNameIndex = rdr.nextRecord().indexOf("Account.Name");
} else {
acctNameIndex = rdr.nextRecord().indexOf("Name");
extractedNameVal = (String)row.get("Account.Name");
}
assertEquals(accountName, rdr.nextRecord().get(acctNameIndex));
assertEquals(accountName, extractedNameVal);
} catch (DataAccessObjectInitializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DataAccessObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
IOUtils.closeQuietly(fis);
}
Expand Down

0 comments on commit ea14bfc

Please sign in to comment.