T4S Unit Test Setup v2.13 or Later

Below is an example of configuring T4S within your unit test, so you can test your own code implementations.

Example unit test using T4S v2.13 or later

@isTest public with sharing class myUnitTest { /** * There needs to be some settings data for Trim__c to be saved. **/ @testSetup static void setup() { fuseit_t4s.TrimPostPackageInstall postinstall = new fuseit_t4s.TrimPostPackageInstall(); Test.testInstall(postinstall, null); fuseit_t4s__Trim__c trim = new fuseit_t4s__Trim__c(); trim.Name = 'Trim sObject 1'; trim.fuseit_t4s__Trim_Light_IP_Address__c = 'https://test'; trim.fuseit_t4s__Trim_Default_Location_ID__c = '1'; trim.fuseit_t4s__Handle_Deletion__c = 'Delete Nothing'; insert trim; fuseit_t4s__Trim_Specification_Property_Set__c containerPropSet = new fuseit_t4s__Trim_Specification_Property_Set__c(); containerPropSet.Name = 'Test Container set'; insert containerPropSet; fuseit_t4s__Trim_Specification_Property_Set__c documentPropSet = new fuseit_t4s__Trim_Specification_Property_Set__c(); documentPropSet.Name = 'Test Record set'; insert documentPropSet; fuseit_t4s__Trim_Specification_Property__c containerProp = new fuseit_t4s__Trim_Specification_Property__c(); containerProp.Name = 'TRIM Container Title'; containerProp.fuseit_t4s__Property_Name__c = 'RecordTitle'; containerProp.fuseit_t4s__Property_Value__c = 'Account - {Name}'; containerProp.fuseit_t4s__Trim_Specification_Property_Set__c = containerPropSet.Id; insert containerProp; fuseit_t4s__Trim_Specification_Property__c docProp = new fuseit_t4s__Trim_Specification_Property__c(); docProp.Name = 'TRIM Document Record Type'; docProp.fuseit_t4s__Property_Name__c = 'RecordRecordType'; docProp.fuseit_t4s__Property_Value__c = 'name:document'; docProp.fuseit_t4s__Trim_Specification_Property_Set__c = documentPropSet.Id; insert docProp; //Trim Setting for Contact records fuseit_t4s__Trim_Setting__c setting = new fuseit_t4s__Trim_Setting__c(); setting.Name = 'Test Setting'; setting.fuseit_t4s__sObject_Name__c = 'Account'; setting.fuseit_t4s__Trim_Container_Uri__c = '2'; setting.fuseit_t4s__Trim_Server__c = trim.Id; setting.fuseit_t4s__Auto_Add_Attachment__c = true; setting.fuseit_t4s__Auto_Delete_Attachment__c = true; setting.fuseit_t4s__Auto_Create_Sub_Container__c = true; setting.fuseit_t4s__Container_Specification_Property_Set__c = containerPropSet.id; setting.fuseit_t4s__Record_Specification_Property_Set__c = documentPropSet.id; setting.fuseit_t4s__sObject_Prefix__c = '001'; insert setting; } static testMethod void testCreateFiles() { Test.startTest(); Set<String> prefixs = new Set<String>(); prefixs.add('001'); fuseit_t4s__Trim_Setting__c setting = [Select Id From fuseit_t4s__Trim_Setting__c Where fuseit_t4s__sObject_Prefix__c in: prefixs And fuseit_t4s__Auto_Add_Attachment__c = true limit 1]; System.assert(setting != null, 'Trim_Setting__c expected'); Account account = new Account(); account.Name = 'TestAcct'; insert account; List<ContentDocumentLink> links = new List<ContentDocumentLink>(); List<ContentVersion> cvs = new List<ContentVersion>(); Integer count = 10; for(Integer i = 0; i < count; i++) { ContentVersion c = new ContentVersion(); c.PathOnClient='C:test.txt'; c.Title = 'Test File ' + i; c.Origin = 'H'; c.VersionData = Blob.valueOf('Test Content'); cvs.add(c); } insert cvs; cvs = [Select Id, ContentDocumentId From ContentVersion]; count = 3; for(Integer i = 0; i < count; i++) { ContentDocumentLink l = new ContentDocumentLink(); l.LinkedEntityId = account.Id; l.ContentDocumentId = cvs[i].ContentDocumentId; l.ShareType = 'V'; links.add(l); } System.debug('---------------- Debug --------- testBulkContentFiles links.size=' + links.size()); insert links; Case c = new Case(); c.AccountId = account.Id; c.Subject = 'Test Case'; c.Status = 'New'; insert c; count++; ContentDocumentLink caseLink = new ContentDocumentLink(); caseLink.LinkedEntityId = c.Id; caseLink.ContentDocumentId = cvs[count].ContentDocumentId; caseLink.ShareType = 'V'; insert caseLink; Test.stopTest(); List<fuseit_t4s__Trim_Record__c> records = fuseit_t4s.TrimConnector.getCombinedRecordsByParentId(c.Id, '', true, true); System.assertEquals(1, records.size(), 'One TrimRecord expected'); fuseit_t4s__Trim_Record__c record = fuseit_t4s.TrimConnector.createTrimRecord(cvs[count].ContentDocumentId, c.Id); System.assertNotEquals(null, record, 'TrimRecords expected'); ContentDocumentLink accLink = new ContentDocumentLink(); accLink.LinkedEntityId = account.Id; accLink.ContentDocumentId = cvs[count].ContentDocumentId; accLink.ShareType = 'V'; insert accLink; records = [Select Id, Name From fuseit_t4s__Trim_Record__c Where fuseit_t4s__Parent_ID__c =: account.Id]; System.assertEquals((count -1), records.size(), 'TrimRecords expected'); List<fuseit_t4s__Trim_Record_Link__c> recordLinks = [Select Id, fuseit_t4s__LinkedEntityId__c, fuseit_t4s__Trim_Record__c From fuseit_t4s__Trim_Record_Link__c]; System.assertEquals(recordLinks.size(), records.size(), 'recordLinks same size expected'); } }