forked from forcedotcom/dataloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for SOQL IN clause based on CSV file values, fix for intermitte…
…nt config props issue tests for SOQL IN clause based on CSV file values, fix for intermittent config props issue
- Loading branch information
1 parent
1c4679a
commit bc625b2
Showing
7 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/com/salesforce/dataloader/action/visitor/AbstractQueryVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2015, salesforce.com, inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
* that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the | ||
* following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and | ||
* the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.salesforce.dataloader.action.visitor; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
|
||
public class AbstractQueryVisitorTest { | ||
@Test | ||
public void testParseInClauseForFileAndColumnName_IN_ValidInput() { | ||
String input = "SELECT name FROM Account WHERE id IN ({c:\\users\\me\\dataloader\\accounts.csv}, {acctid})"; | ||
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_in_ValidInput() { | ||
String input = "SELECT name FROM Account WHERE id in ({c:\\users\\me\\dataloader\\accounts.csv}, {acctid})"; | ||
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_iN_ValidInput() { | ||
String input = "SELECT name FROM Account WHERE id iN ({c:\\users\\me\\dataloader\\accounts.csv}, {acctid})"; | ||
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 ()"; | ||
List<String> result = AbstractQueryVisitor.parseInClauseForFileAndColumnName(input); | ||
assertTrue(result.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testParseInClauseForFileAndColumnName_EmptyInput() { | ||
String input = ""; | ||
List<String> result = AbstractQueryVisitor.parseInClauseForFileAndColumnName(input); | ||
assertTrue(result.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testParseInClauseForFileAndColumnName_MissingBraces() { | ||
String input = "SELECT name FROM Account WHERE id IN ('c:\\users\\me\\dataloader\\accounts.csv', 'acctid')"; | ||
List<String> result = AbstractQueryVisitor.parseInClauseForFileAndColumnName(input); | ||
assertTrue(result.isEmpty()); | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
src/test/java/com/salesforce/dataloader/process/SOQLInClauseFromCSVTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright (c) 2015, salesforce.com, inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
* that the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the | ||
* following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and | ||
* the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.salesforce.dataloader.process; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import com.salesforce.dataloader.TestSetting; | ||
import com.salesforce.dataloader.TestVariant; | ||
import com.salesforce.dataloader.action.OperationInfo; | ||
import com.salesforce.dataloader.action.visitor.AbstractQueryVisitor; | ||
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.soap.partner.sobject.SObject; | ||
import com.sforce.ws.ConnectionException; | ||
|
||
@RunWith(Parameterized.class) | ||
@SuppressWarnings("unused") | ||
public class SOQLInClauseFromCSVTest extends ProcessTestBase { | ||
@Parameterized.Parameters(name = "{0}") | ||
public static Collection<Object[]> getParameters() { | ||
return Arrays.asList( | ||
// partner API | ||
TestVariant.forSettings(TestSetting.BULK_API_DISABLED, TestSetting.BULK_V2_API_DISABLED), | ||
// Bulk API | ||
TestVariant.forSettings(TestSetting.BULK_API_ENABLED, TestSetting.BULK_V2_API_DISABLED), | ||
// Bulk V2 Query API | ||
TestVariant.forSettings(TestSetting.BULK_V2_API_ENABLED)); | ||
} | ||
|
||
private Map<String,String> testConfig; | ||
|
||
@Before | ||
public void setupTestConfig() { | ||
testConfig = getTestConfig(OperationInfo.extract, true); | ||
testConfig.put(AppConfig.PROP_ENTITY, "Account"); | ||
testConfig.put(AppConfig.PROP_ENABLE_EXTRACT_STATUS_OUTPUT, AppConfig.TRUE); | ||
testConfig.remove(AppConfig.PROP_MAPPING_FILE); | ||
} | ||
|
||
public SOQLInClauseFromCSVTest(Map<String, String> config) { | ||
super(config); | ||
} | ||
|
||
private static final String COL_IN_CSV = "Oracle_Id__c"; | ||
private static final String ORACLE_ID_VAL = "oracleIdXyz"; | ||
private static final String NAME_VAL = "acctNameXyz"; | ||
|
||
@Test | ||
public void testSoqlInClauseUsingCSV() throws Exception { | ||
Map<String, String> configMap = getTestConfig(OperationInfo.insert, false); | ||
String accountId = insertAccount(NAME_VAL, ORACLE_ID_VAL); | ||
String extractionFileName = getTestDataDir() + File.separator + "SoqlInClauseFromCSV.csv"; | ||
runExtraction("select name from Account where " | ||
+ COL_IN_CSV | ||
+ " in ({" | ||
+ extractionFileName | ||
+ "}, {" | ||
+ COL_IN_CSV | ||
+ "})"); | ||
validateAccountNameInOutputFile("acctNameXyz"); | ||
} | ||
|
||
private void runExtraction(String extractionQuery) 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); | ||
} | ||
|
||
private String insertAccount(String name, String oracleId) throws ConnectionException { | ||
final SObject account = new SObject(); | ||
account.setType("Account"); | ||
account.setField("Name", name); | ||
account.setField("Oracle_Id__c", oracleId); | ||
String id = getBinding().create(new SObject[]{account})[0].getId(); | ||
assertNotNull(id); | ||
return id; | ||
} | ||
|
||
private void validateAccountNameInOutputFile(final String accountName) 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); | ||
} catch (DataAccessObjectInitializationException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (DataAccessObjectException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} finally { | ||
IOUtils.closeQuietly(fis); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name,Oracle_Id__c | ||
"acctNameXyz","oracleIdXyz" |