-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
2Replies
Need help to coverage my unit test
Hi, i want to cover my class but i don't know what i do that.
public with sharing class LCCTRL_GenBop {
@AuraEnabled
public static void insertFile(Id oppId, String base64FileData, Opportunity recordData) {
try {
Id[] contentDocIdLs = new Id[]{};
ContentDocumentLink[] ctLinkLs = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :oppId];
for(ContentDocumentLink ctLink : ctLinkLs) {
contentDocIdLs.add(ctLink.ContentDocumentId);
}
ContentVersion[] cvLs = [SELECT Id FROM ContentVersion WHERE ContentDocumentId IN :contentDocIdLs AND IsLatest = true AND Type_fileupload__c = 'BOP'];
String fileTitle = 'BOP--'+ (recordData.Name!=null ? recordData.Name : '') + '_V'+(cvLs.size()+1);
ContentVersion cv = new ContentVersion(Type_fileupload__c = 'BOP', VersionData = EncodingUtil.base64Decode(base64FileData), Title = fileTitle, PathOnClient = fileTitle + '.' + 'pdf');
insert cv;
cv = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = : cv.Id];
insert new ContentDocumentLink(LinkedEntityId = oppId, ContentDocumentId = cv.ContentDocumentId);
} catch (AuraHandledException e) {
throw new AuraHandledException(e.getMessage());
}
}
@AuraEnabled
public static Map<String,Object> getData(Id oppId) {
Map<String,Object> dataMap = new Map<String,Object>();
Opportunity opp = [SELECT Id, Name, Customer_Selection_Criteria_Price__c, Customer_Selection_Criteria_Time__c, Customer_Selection_Criteria_Quality__c, Customer_Selection_Criteria_Location__c, Customer_Selection_Criteria_Reputation__c, Customer_Selection_Criteria_Relationship__c,
Account.Name, TOLABEL(Account.Country__c), TOLABEL(Account.Type), Account.Market_cap_Investors__c, Account.Dedicated_to_therapeutic_fields__c, Account.Clinical_or_marketed_product_pipeline__c, Account.Linked_to_other_CDMO__c, Account.Cultural_fit__c, Account.Expertise__c, Account.Capacity__c, Account.Strategic__c, Account.Relationship__c,
Nature_of_the_molecule__c, Z_Indication__c, TOLABEL(Stage_of_Development__c), Sales_expected_at_Peak_Sale__c, Estimated_probability_of_Success__c, When__c, Which_technology__c, First_source__c, Dead_line_to_deliver_the_offer__c, Dead_line_to_select_the_CDMO__c
FROM Opportunity WHERE Id = :oppId LIMIT 1];
dataMap.put('record', opp);
return dataMap;
}
}
I have try this to make test for enter in the method testInsertFile but he doesn't work.
In the test class is my data used in the org for test.
@isTest
public with sharing class TEST_LCCTRL_GenBop {
@TestSetup
static void setup(){
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Account.getRecordTypeInfosByName();
Schema.RecordTypeInfo recordtype = rtMapByName.get('Commercial');
Account account4Test = new Account(name = 'TEST ACCOUNT'
, Country__c = 'US'
, CurrencyIsoCode = 'EUR'
, Type = 'Commercial'
, RecordTypeId = recordtype.RecordTypeId);
insert account4Test;
Product2 product = TestCreate_Product2.Create_Product2();
GMID_Product__c gmid = new GMID_Product__c();
gmid.Z_Commercial_Product__c = product.Id;
gmid.Z_GMID_ext_key__c = 'GMID_EXT_001';
gmid.Z_GMID_GUOM_to_KGM__c = '0';
gmid.Z_GMID_Status__c = true;
gmid.Z_CRI__c = 100;
insert gmid;
Term_of_payment__c temOfPayment = new Term_of_payment__c();
temOfPayment.Z_EN_Description__c = 'TEST';
temOfPayment.Z_Source_date__c = Date.today();
insert temOfPayment;
Opportunity opportunity = new Opportunity();
opportunity.AccountId = account4Test.Id;
opportunity.Z_Product__c = product.Id;
opportunity.Z_GMID_Product__c = gmid.Id;
opportunity.StageName= TRGHDL_Opportunity.QUALIFICATION;
opportunity.Name = 'TEST1';
opportunity.Z_Service_comments__c = 'TEST1';
opportunity.CloseDate = Date.today().addDays(30);
opportunity.Z_Incoterms__c = 'CIP';
opportunity.Z_Incoterms_2__c = 'TEST';
opportunity.Z_Terms_of_Payment__c = temOfPayment.Id;
insert opportunity;
}
@IsTest
private static void testInsertFile(){
String fileData = 'Title';
String fileDateBase64 = EncodingUtil.base64Encode(Blob.valueOf(FileData));
Opportunity opportunity = [SELECT AccountId, StageName FROM Opportunity WHERE Z_Service_comments__c ='TEST1' LIMIT 1];
ContentVersion[] cvLs = [SELECT Id, ContentDocumentId FROM ContentVersion];
Test.startTest();
insert opportunity;
}
@IsTest
private static void getData(){
}
}
-
- DiutG
- July 19, 2022
- Like
- 0
How to write a test class for cover my class ?
Hi, i want to cover my class but i don't know what i do that.
@IsTest
public with sharing class TEST_LCCTRL_GenBulltinSouscription {
private static String TU_PREFIX = 'TEST_TRGHDL_Case_VRSetup';
public static String TYPE_VALIDATOR_PLAN_NAME = '%Bulletin de souscription%';
public static String PLAN_NAME = 'Validation document';
private static String CABINETID = '56789';
private static String URL = 'https://ged-sous/DocuWare/Platform/';
@testSetup
static void TEST_TRGHDL_Case_VRSetup(){
List<TypeValidator__c> LstValidator = new List<TypeValidator__c>{
new TypeValidator__c(Name = '1.1.1 - Justificatif de domicile'),
new TypeValidator__c(Name = '1.1.2 - RIB'),
new TypeValidator__c(Name = '1.1.3 - CNI'),
new TypeValidator__c(Name = '1.1.4 - Tutelle/Curatelle'),
new TypeValidator__c(Name = '1.1.5 - Correspondances'),
new TypeValidator__c(Name = '1.1.6 - Status'),
new TypeValidator__c(Name = '1.1.7 - KBIS'),
new TypeValidator__c(Name = '2.1.1 - Bulletin de souscriptions'),
new TypeValidator__c(Name = '2.1.7 - Origine des fonds'),
new TypeValidator__c(Name = '2.2.1 - Certificat'),
new TypeValidator__c(Name = '2.2.2 - Courrier'),
new TypeValidator__c(Name = '2.3.1 - Chèque'),
new TypeValidator__c(Name = '2.3.2 - Virement'),
new TypeValidator__c(Name = '2.3.5 - FACTA CRS'),
new TypeValidator__c(Name = '1.1.10 - Attestation régimes matrimoniaux'),
new TypeValidator__c(Name = '1.1.11 - Documents complémentaires'),
new TypeValidator__c(Name = '1.1.14 - Justificatif(s) identité Représentant PM et Dirigeant'),
new TypeValidator__c(Name = '1.1.15 - Liasse fiscale'),
new TypeValidator__c(Name = '1.1.16 - Livret de famille'),
new TypeValidator__c(Name = '1.1.17 - PV'),
new TypeValidator__c(Name = '1.1.18 - Offre de prêt'),
new TypeValidator__c(Name = '1.1.19 - Situation patrimoniale'),
new TypeValidator__c(Name = '1.1.20 - Attestation personne âgée'),
new TypeValidator__c(Name = '1.1.8 - Bilan'),
new TypeValidator__c(Name = '1.1.9 - Carton de signatures'),
new TypeValidator__c(Name = '2.1.1 - Bulletin de souscription'),
new TypeValidator__c(Name = '2.1.10 - Bénéficiaires effectifs'),
new TypeValidator__c(Name = '2.1.12 - Attestation Emploi de Fonds Propres'),
new TypeValidator__c(Name = '2.1.8 - LAB/LAT'),
new TypeValidator__c(Name = '2.3.4 - Mandat SEPA'),
new TypeValidator__c(Name = '2.3.5 - FATCA CRS'),
new TypeValidator__c(Name = '2.3.6 - Versement programmé'),
new TypeValidator__c(Name = '1.1.12 - Justificatif(s) identité principal'),
new TypeValidator__c(Name = '1.1.13 - Justificatif(s) identité secondaire')
};
insert LstValidator;
INSEE__c i1 =TEST_SouscriptionDataFactory.genInsee('FRANCE');
i1.Code_Pays_ISO_3166A3__c = 'FRA';
INSEE__c i2 =TEST_SouscriptionDataFactory.genInsee('BELGIQUE');
i2.Code_Pays_ISO_3166A3__c = 'BEL';
insert new INSEE__c[]{i1, i2};
Account accApporteur = TEST_SouscriptionDataFactory.genApporteur(TU_PREFIX+'Apporteur', '4');
accApporteur.ShippingCountry = 'FRANCE';
accApporteur.BillingCountry = 'FRANCE';
accApporteur.Identifiant_Unicia__c = '1884';
accApporteur.Type_de_societe__c = null;
Account accApporteur2 = TEST_SouscriptionDataFactory.genApporteur(TU_PREFIX+'Apporteur2', '4');
accApporteur2.Identifiant_Unicia__c = '1390';
accApporteur2.Type_de_societe__c = null;
insert new Account[]{accApporteur, accApporteur2};
Account accAssociePM = TEST_SouscriptionDataFactory.genAssociePM(TU_PREFIX+'AssociePM1', accApporteur.Id);
Account accAssociePP = TEST_SouscriptionDataFactory.genAssociePP(TU_PREFIX+'AssociePP1', accApporteur.Id, '1');
accAssociePP.Taux_non_resident__c = null;
insert new Account[]{accAssociePM, accAssociePP};
Id rtIdApporteur = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Contact_Apporteur').getRecordTypeId();
Contact contactAssociePP = TEST_SouscriptionDataFactory.genContactPP('ContTUACC1', 'name', accAssociePP.Id);
Contact contactEditique = new Contact(
Salutation = '2',
FirstName = 'toto',
LastName = 'tutu',
RecordTypeId = rtIdApporteur,
AccountId = accApporteur.Id
);
insert new Contact[]{contactAssociePP, contactEditique};
AccountContactRelation acrEditique = [SELECT Id, Roles, AccountId, ContactId FROM AccountContactRelation WHERE AccountId = :accApporteur.Id AND ContactId = :contactEditique.Id LIMIT 1];
acrEditique.Roles = 'Editique';
update acrEditique;
Product2 p = TEST_SouscriptionDataFactory.genProduct(TU_PREFIX+'1');
insert p;
Case cDemembrement = TEST_SouscriptionDataFactory.genSouscriptionDemembrement(true, 'GC', TU_PREFIX+'SOUS2', 'US', 'Démembrement', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
cDemembrement.Type_de_dur_e__c = 'Viager';
Case cVLP = TEST_SouscriptionDataFactory.genSouscriptionVLP(true, 'GC', TU_PREFIX+'VLP', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
cVLP.Type_de_VLP__c = Util_Case.TYPEVLP_CREATION;
Datetime dt = datetime.now().addMonths(3);
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
cVLP.Date_de_debut_de_mandat__c = myDate;
Case c2Contrepartie = TEST_SouscriptionDataFactory.genDemandeContrepartie(cDemembrement, TU_PREFIX+'Ctpr');
insert new Case[]{cDemembrement, c2Contrepartie, cVLP};
Case c = TEST_SouscriptionDataFactory.genSouscriptionPP('GC', TU_PREFIX+'SOUS1', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
insert c;
List<TypeValidatorPlan__c> typeValidatorPlanLs= [SELECT Id FROM TypeValidatorPlan__c WHERE Plan__r.Name = 'Validation document' AND Plan__r.RecordValidationPlan__r.RecordId__c = :c.Id];
System.debug('typeValidatorPlanLs');
System.debug(typeValidatorPlanLs);
Docuware_settings__c setting = (Docuware_settings__c)Util_Test.populatedMock('Docuware_settings__c', null);
setting.CabinetId__c = CABINETID;
setting.Url__c = URL;
insert setting;
}
@IsTest
static void TEST_LCCTRL_GenBulltinSouscription(){
Case c = [SELECT Id, Description_Statut_Souscription__c, Contrepartie__c FROM Case WHERE suppliedCompany = :TU_PREFIX+'SOUS1'];
Test.startTest();
Map<String,Object> result = LCCTRL_GenBulltinSouscription.getRecordForBS(c.Id);
Test.stopTest();
//System.debug('result : ' + result);
System.assertEquals(3, result.values().size());
}
@IsTest
static void TEST_saveBS(){
String url = URL+'FileCabinets/'+ CABINETID + '/Documents';
String body = '{"Id":12345}';
Util_Test.GenericHTTPCalloutMock mock = new Util_Test.GenericHTTPCalloutMock(url,'POST',200,body);
Map<String, HttpCalloutMock> requestsMap = new Map<String, HttpCalloutMock>{url=>mock};
Util_Test.MultiRequestMock multiMock = new Util_Test.MultiRequestMock(requestsMap);
Case c = [SELECT Id, Description_Statut_Souscription__c, Contrepartie__c FROM Case WHERE suppliedCompany = :TU_PREFIX+'SOUS1'];
Test.startTest();
Test.setMock(HttpCalloutMock.class, multiMock);
LCCTRL_GenBulltinSouscription.saveBS(c.Id,'dGVzdA==');
Test.stopTest();
}
}
I have start to write a test class but he doesn't work to enter in the method testInsertFile
@isTest
public with sharing class TEST_LCCTRL_GenBop {
@TestSetup
static void setup(){
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Account.getRecordTypeInfosByName();
Schema.RecordTypeInfo recordtype = rtMapByName.get('Commercial');
Account account4Test = new Account(name = 'TEST ACCOUNT'
, Country__c = 'US'
, CurrencyIsoCode = 'EUR'
, Type = 'Commercial'
, RecordTypeId = recordtype.RecordTypeId);
insert account4Test;
Product2 product = TestCreate_Product2.Create_Product2();
GMID_Product__c gmid = new GMID_Product__c();
gmid.Z_Commercial_Product__c = product.Id;
gmid.Z_GMID_ext_key__c = 'GMID_EXT_001';
gmid.Z_GMID_GUOM_to_KGM__c = '0';
gmid.Z_GMID_Status__c = true;
gmid.Z_CRI__c = 100;
insert gmid;
Term_of_payment__c temOfPayment = new Term_of_payment__c();
temOfPayment.Z_EN_Description__c = 'TEST';
temOfPayment.Z_Source_date__c = Date.today();
insert temOfPayment;
Opportunity opportunity = new Opportunity();
opportunity.AccountId = account4Test.Id;
opportunity.Z_Product__c = product.Id;
opportunity.Z_GMID_Product__c = gmid.Id;
opportunity.StageName= TRGHDL_Opportunity.QUALIFICATION;
opportunity.Name = 'TEST1';
opportunity.Z_Service_comments__c = 'TEST1';
opportunity.CloseDate = Date.today().addDays(30);
opportunity.Z_Incoterms__c = 'CIP';
opportunity.Z_Incoterms_2__c = 'TEST';
opportunity.Z_Terms_of_Payment__c = temOfPayment.Id;
insert opportunity;
}
@IsTest
private static void testInsertFile(){
String fileData = 'Title';
String fileDateBase64 = EncodingUtil.base64Encode(Blob.valueOf(FileData));
Opportunity opportunity = [SELECT AccountId, StageName FROM Opportunity WHERE Z_Service_comments__c ='TEST1' LIMIT 1];
ContentVersion[] cvLs = [SELECT Id, ContentDocumentId FROM ContentVersion];
Test.startTest();
insert opportunity;
}
@IsTest
private static void getData(){
}
}
-
- DiutG
- July 19, 2022
- Like
- 0
Need help to coverage my unit test
Hi, i want to cover my class but i don't know what i do that.
public with sharing class LCCTRL_GenBop {
@AuraEnabled
public static void insertFile(Id oppId, String base64FileData, Opportunity recordData) {
try {
Id[] contentDocIdLs = new Id[]{};
ContentDocumentLink[] ctLinkLs = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :oppId];
for(ContentDocumentLink ctLink : ctLinkLs) {
contentDocIdLs.add(ctLink.ContentDocumentId);
}
ContentVersion[] cvLs = [SELECT Id FROM ContentVersion WHERE ContentDocumentId IN :contentDocIdLs AND IsLatest = true AND Type_fileupload__c = 'BOP'];
String fileTitle = 'BOP--'+ (recordData.Name!=null ? recordData.Name : '') + '_V'+(cvLs.size()+1);
ContentVersion cv = new ContentVersion(Type_fileupload__c = 'BOP', VersionData = EncodingUtil.base64Decode(base64FileData), Title = fileTitle, PathOnClient = fileTitle + '.' + 'pdf');
insert cv;
cv = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = : cv.Id];
insert new ContentDocumentLink(LinkedEntityId = oppId, ContentDocumentId = cv.ContentDocumentId);
} catch (AuraHandledException e) {
throw new AuraHandledException(e.getMessage());
}
}
@AuraEnabled
public static Map<String,Object> getData(Id oppId) {
Map<String,Object> dataMap = new Map<String,Object>();
Opportunity opp = [SELECT Id, Name, Customer_Selection_Criteria_Price__c, Customer_Selection_Criteria_Time__c, Customer_Selection_Criteria_Quality__c, Customer_Selection_Criteria_Location__c, Customer_Selection_Criteria_Reputation__c, Customer_Selection_Criteria_Relationship__c,
Account.Name, TOLABEL(Account.Country__c), TOLABEL(Account.Type), Account.Market_cap_Investors__c, Account.Dedicated_to_therapeutic_fields__c, Account.Clinical_or_marketed_product_pipeline__c, Account.Linked_to_other_CDMO__c, Account.Cultural_fit__c, Account.Expertise__c, Account.Capacity__c, Account.Strategic__c, Account.Relationship__c,
Nature_of_the_molecule__c, Z_Indication__c, TOLABEL(Stage_of_Development__c), Sales_expected_at_Peak_Sale__c, Estimated_probability_of_Success__c, When__c, Which_technology__c, First_source__c, Dead_line_to_deliver_the_offer__c, Dead_line_to_select_the_CDMO__c
FROM Opportunity WHERE Id = :oppId LIMIT 1];
dataMap.put('record', opp);
return dataMap;
}
}
I have try this to make test for enter in the method testInsertFile but he doesn't work.
In the test class is my data used in the org for test.
@isTest
public with sharing class TEST_LCCTRL_GenBop {
@TestSetup
static void setup(){
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Account.getRecordTypeInfosByName();
Schema.RecordTypeInfo recordtype = rtMapByName.get('Commercial');
Account account4Test = new Account(name = 'TEST ACCOUNT'
, Country__c = 'US'
, CurrencyIsoCode = 'EUR'
, Type = 'Commercial'
, RecordTypeId = recordtype.RecordTypeId);
insert account4Test;
Product2 product = TestCreate_Product2.Create_Product2();
GMID_Product__c gmid = new GMID_Product__c();
gmid.Z_Commercial_Product__c = product.Id;
gmid.Z_GMID_ext_key__c = 'GMID_EXT_001';
gmid.Z_GMID_GUOM_to_KGM__c = '0';
gmid.Z_GMID_Status__c = true;
gmid.Z_CRI__c = 100;
insert gmid;
Term_of_payment__c temOfPayment = new Term_of_payment__c();
temOfPayment.Z_EN_Description__c = 'TEST';
temOfPayment.Z_Source_date__c = Date.today();
insert temOfPayment;
Opportunity opportunity = new Opportunity();
opportunity.AccountId = account4Test.Id;
opportunity.Z_Product__c = product.Id;
opportunity.Z_GMID_Product__c = gmid.Id;
opportunity.StageName= TRGHDL_Opportunity.QUALIFICATION;
opportunity.Name = 'TEST1';
opportunity.Z_Service_comments__c = 'TEST1';
opportunity.CloseDate = Date.today().addDays(30);
opportunity.Z_Incoterms__c = 'CIP';
opportunity.Z_Incoterms_2__c = 'TEST';
opportunity.Z_Terms_of_Payment__c = temOfPayment.Id;
insert opportunity;
}
@IsTest
private static void testInsertFile(){
String fileData = 'Title';
String fileDateBase64 = EncodingUtil.base64Encode(Blob.valueOf(FileData));
Opportunity opportunity = [SELECT AccountId, StageName FROM Opportunity WHERE Z_Service_comments__c ='TEST1' LIMIT 1];
ContentVersion[] cvLs = [SELECT Id, ContentDocumentId FROM ContentVersion];
Test.startTest();
insert opportunity;
}
@IsTest
private static void getData(){
}
}

- DiutG
- July 19, 2022
- Like
- 0
How to write a test class for cover my class ?
Hi, i want to cover my class but i don't know what i do that.
@IsTest
public with sharing class TEST_LCCTRL_GenBulltinSouscription {
private static String TU_PREFIX = 'TEST_TRGHDL_Case_VRSetup';
public static String TYPE_VALIDATOR_PLAN_NAME = '%Bulletin de souscription%';
public static String PLAN_NAME = 'Validation document';
private static String CABINETID = '56789';
private static String URL = 'https://ged-sous/DocuWare/Platform/';
@testSetup
static void TEST_TRGHDL_Case_VRSetup(){
List<TypeValidator__c> LstValidator = new List<TypeValidator__c>{
new TypeValidator__c(Name = '1.1.1 - Justificatif de domicile'),
new TypeValidator__c(Name = '1.1.2 - RIB'),
new TypeValidator__c(Name = '1.1.3 - CNI'),
new TypeValidator__c(Name = '1.1.4 - Tutelle/Curatelle'),
new TypeValidator__c(Name = '1.1.5 - Correspondances'),
new TypeValidator__c(Name = '1.1.6 - Status'),
new TypeValidator__c(Name = '1.1.7 - KBIS'),
new TypeValidator__c(Name = '2.1.1 - Bulletin de souscriptions'),
new TypeValidator__c(Name = '2.1.7 - Origine des fonds'),
new TypeValidator__c(Name = '2.2.1 - Certificat'),
new TypeValidator__c(Name = '2.2.2 - Courrier'),
new TypeValidator__c(Name = '2.3.1 - Chèque'),
new TypeValidator__c(Name = '2.3.2 - Virement'),
new TypeValidator__c(Name = '2.3.5 - FACTA CRS'),
new TypeValidator__c(Name = '1.1.10 - Attestation régimes matrimoniaux'),
new TypeValidator__c(Name = '1.1.11 - Documents complémentaires'),
new TypeValidator__c(Name = '1.1.14 - Justificatif(s) identité Représentant PM et Dirigeant'),
new TypeValidator__c(Name = '1.1.15 - Liasse fiscale'),
new TypeValidator__c(Name = '1.1.16 - Livret de famille'),
new TypeValidator__c(Name = '1.1.17 - PV'),
new TypeValidator__c(Name = '1.1.18 - Offre de prêt'),
new TypeValidator__c(Name = '1.1.19 - Situation patrimoniale'),
new TypeValidator__c(Name = '1.1.20 - Attestation personne âgée'),
new TypeValidator__c(Name = '1.1.8 - Bilan'),
new TypeValidator__c(Name = '1.1.9 - Carton de signatures'),
new TypeValidator__c(Name = '2.1.1 - Bulletin de souscription'),
new TypeValidator__c(Name = '2.1.10 - Bénéficiaires effectifs'),
new TypeValidator__c(Name = '2.1.12 - Attestation Emploi de Fonds Propres'),
new TypeValidator__c(Name = '2.1.8 - LAB/LAT'),
new TypeValidator__c(Name = '2.3.4 - Mandat SEPA'),
new TypeValidator__c(Name = '2.3.5 - FATCA CRS'),
new TypeValidator__c(Name = '2.3.6 - Versement programmé'),
new TypeValidator__c(Name = '1.1.12 - Justificatif(s) identité principal'),
new TypeValidator__c(Name = '1.1.13 - Justificatif(s) identité secondaire')
};
insert LstValidator;
INSEE__c i1 =TEST_SouscriptionDataFactory.genInsee('FRANCE');
i1.Code_Pays_ISO_3166A3__c = 'FRA';
INSEE__c i2 =TEST_SouscriptionDataFactory.genInsee('BELGIQUE');
i2.Code_Pays_ISO_3166A3__c = 'BEL';
insert new INSEE__c[]{i1, i2};
Account accApporteur = TEST_SouscriptionDataFactory.genApporteur(TU_PREFIX+'Apporteur', '4');
accApporteur.ShippingCountry = 'FRANCE';
accApporteur.BillingCountry = 'FRANCE';
accApporteur.Identifiant_Unicia__c = '1884';
accApporteur.Type_de_societe__c = null;
Account accApporteur2 = TEST_SouscriptionDataFactory.genApporteur(TU_PREFIX+'Apporteur2', '4');
accApporteur2.Identifiant_Unicia__c = '1390';
accApporteur2.Type_de_societe__c = null;
insert new Account[]{accApporteur, accApporteur2};
Account accAssociePM = TEST_SouscriptionDataFactory.genAssociePM(TU_PREFIX+'AssociePM1', accApporteur.Id);
Account accAssociePP = TEST_SouscriptionDataFactory.genAssociePP(TU_PREFIX+'AssociePP1', accApporteur.Id, '1');
accAssociePP.Taux_non_resident__c = null;
insert new Account[]{accAssociePM, accAssociePP};
Id rtIdApporteur = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Contact_Apporteur').getRecordTypeId();
Contact contactAssociePP = TEST_SouscriptionDataFactory.genContactPP('ContTUACC1', 'name', accAssociePP.Id);
Contact contactEditique = new Contact(
Salutation = '2',
FirstName = 'toto',
LastName = 'tutu',
RecordTypeId = rtIdApporteur,
AccountId = accApporteur.Id
);
insert new Contact[]{contactAssociePP, contactEditique};
AccountContactRelation acrEditique = [SELECT Id, Roles, AccountId, ContactId FROM AccountContactRelation WHERE AccountId = :accApporteur.Id AND ContactId = :contactEditique.Id LIMIT 1];
acrEditique.Roles = 'Editique';
update acrEditique;
Product2 p = TEST_SouscriptionDataFactory.genProduct(TU_PREFIX+'1');
insert p;
Case cDemembrement = TEST_SouscriptionDataFactory.genSouscriptionDemembrement(true, 'GC', TU_PREFIX+'SOUS2', 'US', 'Démembrement', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
cDemembrement.Type_de_dur_e__c = 'Viager';
Case cVLP = TEST_SouscriptionDataFactory.genSouscriptionVLP(true, 'GC', TU_PREFIX+'VLP', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
cVLP.Type_de_VLP__c = Util_Case.TYPEVLP_CREATION;
Datetime dt = datetime.now().addMonths(3);
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
cVLP.Date_de_debut_de_mandat__c = myDate;
Case c2Contrepartie = TEST_SouscriptionDataFactory.genDemandeContrepartie(cDemembrement, TU_PREFIX+'Ctpr');
insert new Case[]{cDemembrement, c2Contrepartie, cVLP};
Case c = TEST_SouscriptionDataFactory.genSouscriptionPP('GC', TU_PREFIX+'SOUS1', accAssociePM.Id, accAssociePM.Id, accApporteur.Id, p.Id);
insert c;
List<TypeValidatorPlan__c> typeValidatorPlanLs= [SELECT Id FROM TypeValidatorPlan__c WHERE Plan__r.Name = 'Validation document' AND Plan__r.RecordValidationPlan__r.RecordId__c = :c.Id];
System.debug('typeValidatorPlanLs');
System.debug(typeValidatorPlanLs);
Docuware_settings__c setting = (Docuware_settings__c)Util_Test.populatedMock('Docuware_settings__c', null);
setting.CabinetId__c = CABINETID;
setting.Url__c = URL;
insert setting;
}
@IsTest
static void TEST_LCCTRL_GenBulltinSouscription(){
Case c = [SELECT Id, Description_Statut_Souscription__c, Contrepartie__c FROM Case WHERE suppliedCompany = :TU_PREFIX+'SOUS1'];
Test.startTest();
Map<String,Object> result = LCCTRL_GenBulltinSouscription.getRecordForBS(c.Id);
Test.stopTest();
//System.debug('result : ' + result);
System.assertEquals(3, result.values().size());
}
@IsTest
static void TEST_saveBS(){
String url = URL+'FileCabinets/'+ CABINETID + '/Documents';
String body = '{"Id":12345}';
Util_Test.GenericHTTPCalloutMock mock = new Util_Test.GenericHTTPCalloutMock(url,'POST',200,body);
Map<String, HttpCalloutMock> requestsMap = new Map<String, HttpCalloutMock>{url=>mock};
Util_Test.MultiRequestMock multiMock = new Util_Test.MultiRequestMock(requestsMap);
Case c = [SELECT Id, Description_Statut_Souscription__c, Contrepartie__c FROM Case WHERE suppliedCompany = :TU_PREFIX+'SOUS1'];
Test.startTest();
Test.setMock(HttpCalloutMock.class, multiMock);
LCCTRL_GenBulltinSouscription.saveBS(c.Id,'dGVzdA==');
Test.stopTest();
}
}
I have start to write a test class but he doesn't work to enter in the method testInsertFile
@isTest
public with sharing class TEST_LCCTRL_GenBop {
@TestSetup
static void setup(){
Map<String,Schema.RecordTypeInfo> rtMapByName = Schema.SObjectType.Account.getRecordTypeInfosByName();
Schema.RecordTypeInfo recordtype = rtMapByName.get('Commercial');
Account account4Test = new Account(name = 'TEST ACCOUNT'
, Country__c = 'US'
, CurrencyIsoCode = 'EUR'
, Type = 'Commercial'
, RecordTypeId = recordtype.RecordTypeId);
insert account4Test;
Product2 product = TestCreate_Product2.Create_Product2();
GMID_Product__c gmid = new GMID_Product__c();
gmid.Z_Commercial_Product__c = product.Id;
gmid.Z_GMID_ext_key__c = 'GMID_EXT_001';
gmid.Z_GMID_GUOM_to_KGM__c = '0';
gmid.Z_GMID_Status__c = true;
gmid.Z_CRI__c = 100;
insert gmid;
Term_of_payment__c temOfPayment = new Term_of_payment__c();
temOfPayment.Z_EN_Description__c = 'TEST';
temOfPayment.Z_Source_date__c = Date.today();
insert temOfPayment;
Opportunity opportunity = new Opportunity();
opportunity.AccountId = account4Test.Id;
opportunity.Z_Product__c = product.Id;
opportunity.Z_GMID_Product__c = gmid.Id;
opportunity.StageName= TRGHDL_Opportunity.QUALIFICATION;
opportunity.Name = 'TEST1';
opportunity.Z_Service_comments__c = 'TEST1';
opportunity.CloseDate = Date.today().addDays(30);
opportunity.Z_Incoterms__c = 'CIP';
opportunity.Z_Incoterms_2__c = 'TEST';
opportunity.Z_Terms_of_Payment__c = temOfPayment.Id;
insert opportunity;
}
@IsTest
private static void testInsertFile(){
String fileData = 'Title';
String fileDateBase64 = EncodingUtil.base64Encode(Blob.valueOf(FileData));
Opportunity opportunity = [SELECT AccountId, StageName FROM Opportunity WHERE Z_Service_comments__c ='TEST1' LIMIT 1];
ContentVersion[] cvLs = [SELECT Id, ContentDocumentId FROM ContentVersion];
Test.startTest();
insert opportunity;
}
@IsTest
private static void getData(){
}
}

- DiutG
- July 19, 2022
- Like
- 0