From 939c5bffd6971dc76416b229e8f92746cf7ab07a Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Mon, 5 Feb 2024 23:45:52 -0800 Subject: [PATCH] additional test for polymorphic relationships Test that a CSV file can contain records that map a relationship field to different parent types if the relationship is a polymorphic relationship. --- .../process/CsvProcessAttachmentTest.java | 13 ++++++++----- .../dataloader/process/ProcessTestBase.java | 1 + .../data/polymorphicRelationshipInAttachment.csv | 5 +++-- .../data/polymorphicRelationshipInAttachmentMap.sdl | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/salesforce/dataloader/process/CsvProcessAttachmentTest.java b/src/test/java/com/salesforce/dataloader/process/CsvProcessAttachmentTest.java index 3eae56bd..f2ba6699 100644 --- a/src/test/java/com/salesforce/dataloader/process/CsvProcessAttachmentTest.java +++ b/src/test/java/com/salesforce/dataloader/process/CsvProcessAttachmentTest.java @@ -32,7 +32,6 @@ import com.salesforce.dataloader.action.progress.ILoaderProgress; import com.salesforce.dataloader.config.Config; import com.salesforce.dataloader.controller.Controller; -import com.salesforce.dataloader.dyna.RelationshipField; import com.salesforce.dataloader.exception.DataAccessObjectException; import com.salesforce.dataloader.exception.ProcessInitializationException; import com.salesforce.dataloader.exception.UnsupportedOperationException; @@ -116,14 +115,18 @@ public void testPolymorphicRelationshipInAttachment() throws ProcessInitializati AccountGenerator acctGen = new AccountGenerator(); SObject[] parentAccts = new SObject[1]; parentAccts[0] = acctGen.getObject(0, false); - // value of Oracle_id__c = 1-000000 SaveResult[] results = getBinding().create(parentAccts); parentAccts[0].addField("id", results[0]); - + + ContactGenerator contactGen = new ContactGenerator(); + SObject[] parentContacts = new SObject[1]; + parentContacts[0] = contactGen.getObject(0, false); + // value of Oracle_id__c = 1-000000 + results = getBinding().create(parentContacts); + parentContacts[0].addField("id", results[0]); + configMap.put(Config.ENTITY, "Attachment"); - RelationshipField parentRel = new RelationshipField("Account", "Parent"); - parentRel.setParentFieldName(DEFAULT_ACCOUNT_EXT_ID_FIELD); runProcess(configMap, 1); } diff --git a/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java b/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java index 40073ce5..770e6a51 100644 --- a/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java +++ b/src/test/java/com/salesforce/dataloader/process/ProcessTestBase.java @@ -487,6 +487,7 @@ public SObject getObject(int i, boolean negativeTest) { contact.setField("Title", titleValue); contact.setField("Phone", "415-555-" + seqStr); contact.setField(DEFAULT_CONTACT_EXT_ID_FIELD, (double) i); + contact.setField("Email", "contact"+i+"@testcustomer.com"); return contact; } diff --git a/src/test/resources/testfiles/data/polymorphicRelationshipInAttachment.csv b/src/test/resources/testfiles/data/polymorphicRelationshipInAttachment.csv index 8635f057..86cec899 100644 --- a/src/test/resources/testfiles/data/polymorphicRelationshipInAttachment.csv +++ b/src/test/resources/testfiles/data/polymorphicRelationshipInAttachment.csv @@ -1,2 +1,3 @@ -Name,Body,Parent:Account-Oracle_Id__c -TestAttachment_01.txt,"target/test-classes/testfiles/data/attachment.txt","1-000000" \ No newline at end of file +Name,Body,Parent:Account-Oracle_Id__c,Parent:Contact-Email +accountAttachment.txt,"target/test-classes/testfiles/data/attachment.txt","1-000000","" +contactAttachment.txt,"target/test-classes/testfiles/data/attachment.txt","","contact0@testcustomer.com" \ No newline at end of file diff --git a/src/test/resources/testfiles/data/polymorphicRelationshipInAttachmentMap.sdl b/src/test/resources/testfiles/data/polymorphicRelationshipInAttachmentMap.sdl index 75245760..45f05370 100644 --- a/src/test/resources/testfiles/data/polymorphicRelationshipInAttachmentMap.sdl +++ b/src/test/resources/testfiles/data/polymorphicRelationshipInAttachmentMap.sdl @@ -2,4 +2,5 @@ # salesforceFieldName=csvFieldName Name=Name Body=Body -Parent\:Account-Oracle_Id__c=Parent\:Account-Oracle_Id__c \ No newline at end of file +Parent\:Account-Oracle_Id__c=Parent\:Account-Oracle_Id__c +Parent\:Contact-Email=Parent\:Contact-Email \ No newline at end of file