Skip to content

Commit

Permalink
additional tests for soql in clause
Browse files Browse the repository at this point in the history
additional tests for soql in clause
  • Loading branch information
ashitsalesforce committed Jan 19, 2025
1 parent bc625b2 commit 68584e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public void testParseInClauseForFileAndColumnName_iN_ValidInput() {
assertEquals("acctid", result.get(1));
}


@Test
public void testParseInClauseForFileAndColumnNameWithAndValidInput() {
String input = "SELECT name FROM Account WHERE id iN ({c:\\users\\me\\dataloader\\accounts.csv}, {acctid}) AND name='bar'";
List<String> result = AbstractQueryVisitor.parseInClauseForFileAndColumnName(input);
assertEquals(2, result.size());
assertEquals("c:\\users\\me\\dataloader\\accounts.csv", result.get(0));
assertEquals("acctid", result.get(1));
}
@Test
public void testParseInClauseForFileAndColumnName_InvalidInput() {
String input = "SELECT name FROM Account WHERE id IN ()";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,31 @@ public SOQLInClauseFromCSVTest(Map<String, String> config) {
@Test
public void testSoqlInClauseUsingCSV() throws Exception {
Map<String, String> configMap = getTestConfig(OperationInfo.insert, false);
String accountId = insertAccount(NAME_VAL, ORACLE_ID_VAL);
String accountId1 = insertAccount(NAME_VAL, ORACLE_ID_VAL);
String accountId2 = insertAccount(NAME_VAL+"2", ORACLE_ID_VAL+"2");
String extractionFileName = getTestDataDir() + File.separator + "SoqlInClauseFromCSV.csv";
runExtraction("select name from Account where "
+ COL_IN_CSV
+ " in ({"
+ extractionFileName
+ "}, {"
+ COL_IN_CSV
+ "})");
validateAccountNameInOutputFile("acctNameXyz");
+ "}) OR Name = '" + NAME_VAL + "2' ORDER BY Name", 2);
validateAccountNamesInOutputFile(NAME_VAL, 2);
runExtraction("select name from Account where Name = '" + NAME_VAL + "' AND "
+ COL_IN_CSV
+ " in ({"
+ extractionFileName
+ "}, {"
+ COL_IN_CSV
+ "})", 1);
validateAccountNamesInOutputFile(NAME_VAL, 1);
}

private void runExtraction(String extractionQuery) throws ProcessInitializationException, DataAccessObjectException {
private void runExtraction(String extractionQuery, int numSuccesses) throws ProcessInitializationException, DataAccessObjectException {
testConfig.put(AppConfig.PROP_EXTRACT_SOQL, extractionQuery);
testConfig.put(AppConfig.PROP_LIMIT_OUTPUT_TO_QUERY_FIELDS, AppConfig.TRUE);
runProcess(testConfig, 1, true);
runProcess(testConfig, numSuccesses, true);
}

private String insertAccount(String name, String oracleId) throws ConnectionException {
Expand All @@ -121,16 +130,20 @@ private String insertAccount(String name, String oracleId) throws ConnectionExce
return id;
}

private void validateAccountNameInOutputFile(final String accountName) throws IOException {
private void validateAccountNamesInOutputFile(
final String accountNamePrefix, final int count) throws IOException {

FileInputStream fis = new FileInputStream(new File(testConfig.get(AppConfig.PROP_DAO_NAME)));
try {
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(accountName, extractedNameVal);
for (int i = 0; i < count; i++) {
String extractedNameVal = (String) row.get("Name");
assertTrue(extractedNameVal.startsWith(accountNamePrefix));
row = rdr.readTableRow();
}
} catch (DataAccessObjectInitializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit 68584e6

Please sign in to comment.