Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USER_DEBUG [21]|DEBUG|ev: (EscrowValidator__mdt:{Username__c=Test, Pass__c=123, Acces_granted__c=false, Token__c=123456, Id=m000U00000002tNQAQ})
- USER_DEBUG [25]|DEBUG|pageRef: System.PageReference[/apex/escrowlink?token=123456]
- DEBUG|An exception accId occurred: List has no rows for assignment to SObject
- public without sharing class Escrowlink{
- public List<ContentDistribution> urlsContentDistribution {get;set;}
- public map<string,string> urlmap{get;set;}
- public Id accId;
- public Escrowlink(Apexpages.StandardController con){
- urlsContentDistribution = new List<ContentDistribution>();
- urlmap = new map<string,string>();
- try{
- string token = apexpages.currentpage().getparameters().get('token');
- accId = [SELECT id , Token__c FROM Account WHERE Token__c =:token LIMIT 1].id;
- }
- catch(Exception e){
- System.debug('An exception accId occurred: ' + e.getMessage());
- }
- try{
- urlsContentDistribution = [SELECT DistributionPublicUrl, ContentDownloadURL ,name FROM ContentDistribution WHERE RelatedRecordId = :accId];
- for(ContentDistribution m:urlsContentDistribution){
- urlmap.put(m.name,m.DistributionPublicUrl);
- }
- }
- catch(Exception e){
- System.debug('An exception idsContentdocument occurred : ' + e.getMessage());
- }
- }
- }
- @istest
- public class EscrowLinkTest {
- static testmethod void escrowlinktest(){
- EscrowLogin.testCase = 'Unittest1';
- Account acc = new Account(Name='accounttest',Token__c='123456');
- insert acc;
- ContentVersion cv=new Contentversion();
- cv.title='ABC';
- cv.PathOnClient ='test';
- Blob b=Blob.valueOf('Unit Test Attachment Body');
- cv.versiondata=EncodingUtil.base64Decode('Unit Test Attachment Body');
- insert cv;
- ContentDistribution contentdist = new ContentDistribution(Name='contentdist',RelatedRecordId = acc.id, ContentVersionId= cv.id);
- insert contentdist;
- List<EscrowValidator__mdt> ev = [SELECT Username__c , Pass__c, Acces_granted__c, Token__c
- FROM EscrowValidator__mdt
- WHERE Unittest__c = :EscrowLogin.testCase];
- system.debug('ev: '+ev);
- PageReference pageRef = Page.EscrowLink;
- pageRef.getParameters().put('token',ev[0].Token__c);
- system.debug('pageRef: '+pageRef);
- Apexpages.StandardController sc = new Apexpages.standardController(acc);
- EscrowLink ext = new EscrowLink(sc);
- system.debug('sc: '+sc);
- System.assertEquals(ext.urlmap.get(contentdist.DistributionPublicUrl), contentdist.DistributionPublicUrl);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement