From ea14bfcb39479c7cbac21aaa6cc4deb884f7208d Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Fri, 13 Dec 2024 10:29:34 -0800 Subject: [PATCH] Tests should use Data Loader's CSVFileReader instead of wsc FileReader Tests should use Data Loader's CSVFileReader instead of wsc FileReader --- .../process/CsvEncodingProcessTest.java | 19 +++++++++++++--- .../CsvExtractAggregateQueryProcessTest.java | 22 ++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/salesforce/dataloader/process/CsvEncodingProcessTest.java b/src/test/java/com/salesforce/dataloader/process/CsvEncodingProcessTest.java index 9edf6bed..9049e47e 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvEncodingProcessTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvEncodingProcessTest.java @@ -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; @@ -120,9 +124,18 @@ private Map getBulkUnicodeExtractConfig(String soql) { private void validateExtraction(final String name, final Map 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); } diff --git a/src/test/java/com/salesforce/dataloader/process/CsvExtractAggregateQueryProcessTest.java b/src/test/java/com/salesforce/dataloader/process/CsvExtractAggregateQueryProcessTest.java index 6370c348..425afa17 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvExtractAggregateQueryProcessTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvExtractAggregateQueryProcessTest.java @@ -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; @@ -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); }