0% found this document useful (0 votes)
8 views4 pages

Test Data Factory

The document describes the Apex Class 'TestDataFactory', a utility class designed for setting up test data across various applications. It includes methods for creating account records, patient records, hospitals, test orders, and accessioning users, along with their respective wrappers for data handling. The modification log details updates and enhancements made to the class functionalities over time.

Uploaded by

sauravgodbole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Test Data Factory

The document describes the Apex Class 'TestDataFactory', a utility class designed for setting up test data across various applications. It includes methods for creating account records, patient records, hospitals, test orders, and accessioning users, along with their respective wrappers for data handling. The modification log details updates and enhancements made to the class functionalities over time.

Uploaded by

sauravgodbole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

*
***********************************************************************************
****************************************
* Apex Class Name - TestDataFactory
* Version - 0.5
* Created Date - 16-Jan-2025
* Function - Utility class for test data setup for all applications.
* Modification Log :
* --------------------------------------------------------------------------------
* User Story Date Description
* ---------------- ----------------------- ---------------------
* CDP-6583, 7384 16-January-2025 Initial version.
* CDP-7304 17-January-2025 Added
createAccessioningUser to Create Accessioner User
* CDP-7304 23-January-2025 Added createTestOrder,
addSpecimentoOrder, createAccessioningUser,

assignAccessioningPermissionSet methods.
* CDP-9222 11-April-2025 Updated AccountWrapper
and createAccount method.
* CDP-11401 05-May-2025 Updated
createAccessioningUser method , added lab assignment field.
*
***********************************************************************************
******************************************
*/

@isTest
public without sharing class TestDataFactory {
/**
* @description : Utility AccountWrapper wrapper class
**/
public class AccountWrapper{
public string Name ;
public string firstName ;
public string lastName ;
public Id RecordtypeId ;
public Id ParentId ;
public string ClientSpecialInstruction ;
}
/**
* @description : Utility SpecimenDetailsInputWrapper wrapper class
**/
public class SpecimenDetailsInputWrapper{
public String orderId;
public String specimenId;
public String physicalSpecimenId;
public Date collectionDate;
public Time collectionTime;
public Date receivedDate;
public Time receivedTime;
public String timeZone;
public String bodySite;
public String primarySite;
public Boolean isMetastasis;
public String specimenType;
public Decimal coldIschemicDuration;
public String fixative;
public String otherFixative;
public Decimal fixationDuration;
public Map<String,Integer> specimenTransportMap;
public Boolean isColdUnknown;
public Boolean isFixativeUnknown;
public Boolean isFixationDurationUnknown;
}
/**
* @description : Utility method to create account record.
**/
public static Account createAccount(AccountWrapper accRecord) {
Account accRec = new Account();
[Link] = [Link];
if([Link] == UTIL_Constants.patientRecordTypeId){
[Link] = [Link];
[Link] = [Link];
}else{
[Link] = [Link];
[Link] = [Link];
accRec.Client_Special_Instructions__c= 'This is a Test Data';
}
insert accRec;
return accRec;
}
/**
* @description : Utility method to create patient record.
**/
public static Account createPatient() {
AccountWrapper patient = new AccountWrapper();
[Link] = 'Sania';
[Link] = 'Mirza';
[Link] = UTIL_Constants.patientRecordTypeId;
return createAccount(patient);
}
/**
* @description : Utility method to create test hospital based on name and
parent hospital.
**/
public static Account createHospital(String hospitalName,Id parentId) {
AccountWrapper hospital = new AccountWrapper();
[Link] = hospitalName;
[Link] = UTIL_Constants.approvedAccountRecordTypeId;
[Link] = parentId;

return createAccount(hospital);
}
/**
* @description : Utility method to create test hospitals.
**/
public static List<Account> createTestHospitals() {
List<Account> hospitalList = new List<Account>();
Account parenthospital = createHospital('Apollo Hospital','');
Account childhospital = createHospital('MGM Hospital',[Link]);
[Link](parenthospital);
[Link](childhospital);
return hospitalList;
}
/**
* @description : Utility method to get parent hospital record.
**/
public static Account getParentHospital() {
return createTestHospitals()[0];
}
/**
* @description : Utility method to get child hospital record.
**/
public static Account getchildHospital() {
List<Account> hospitalList = createTestHospitals();
Integer childIndex = [Link]() - 1;
Account childHospital = hospitalList[childIndex];
return childHospital;
}
/**
* @description : Utility method to create orer based on account Id
**/
public static Order createTestOrder(id accountId){
Order TestOrder = new Order(AccountId = accountId, Status = 'Draft',
EffectiveDate = [Link]());
insert testOrder;
addSpecimentoOrder([Link]);
return testOrder;

}
/**
* @description : Utility method to create SpecimenDetailsInputWrapper based on
order id.
**/
public static void addSpecimentoOrder( Id testOrderId){
SpecimenDetailsInputWrapper inputWrapper = new
SpecimenDetailsInputWrapper();
[Link] = testOrderId;
[Link] = 'Specimen-001';
[Link] = 'test-001';
[Link] = [Link]();
[Link] = [Link](10, 30, 0, 1);
[Link] = [Link]();
[Link] = [Link](11, 0, 0, 0);
[Link] = 'EST';
[Link] = 'Test';
[Link] = 'Paraffin Tissue';
[Link] = true;
[Link] = 123456.00;
[Link] = 'Other';
[Link] = 'Test';
[Link] = 12345678.00;
[Link] = new Map<String, Integer>{'Block' => 1,
'Smear - Unstained Slide(s)' => 4};
[Link] = false;
[Link] = false;
[Link] = false;
String specimenWrapper = [Link](inputWrapper);
List<AC_SpecimenController.SpecimenDetailsOutputWrapper> result =
AC_SpecimenController.getcreatedSpecimenRecords(specimenWrapper);
}
/**
* @description creating test user with Accessioner profile
**/
public static User createAccessioningUser(){
Profile p = [SELECT Id FROM Profile WHERE Name = 'Accessioning' Limit 1];
User testUser = new User();
[Link] = 'accuser';
[Link] = 'accessioninguser@[Link]';
[Link] = 'John';
[Link] = [Link];
[Link] = true;
[Link] = 'accessioninguser@[Link]';
[Link] = 'America/Chicago';
[Link] = 'en_US';
[Link] = 'UTF-8';
[Link] = 'en_US';
[Link] = 'AV';
testUser.Accession_Lab__c = 'NeoGenomics California';
insert testUser;
assignAccessioningPermissionSet([Link]);
return testUser;
}

/**
* @description creating test user with Accessioner profile
**/
public static void assignAccessioningPermissionSet(Id userId){
User testUser = [Select Id ,[Link] From User where Id =:userId];
if([Link] =='Accessioning'){
List<PermissionSetAssignment> permissionSetList = new
List<PermissionSetAssignment>();
List<PermissionSet> HealthCloudPermissionSetLicense =[select id ,Label
from PermissionSet where Name = 'HealthCloudPermissionSetLicense'];
List<PermissionSet> HealthCloudMemberServices =[select id ,Label from
PermissionSet where Name = 'HealthCloudMemberServices'];
List<PermissionSet> HealthCloudFoundation =[select id ,Label from
PermissionSet where Name = 'HealthCloudFoundation'];
List<PermissionSet> FetchListAPI =[select id ,Label from PermissionSet
where Name = 'FetchListAPI'];
List<PermissionSet> NeoHelix_Accessioning_Permission_Set =[select
id ,Label from PermissionSet where Name = 'NeoHelix_Accessioning_Permission_Set'];
PermissionSetAssignment NeoHelix_Accessioning_Permission_SetAssignment
= new PermissionSetAssignment (PermissionSetId =
NeoHelix_Accessioning_Permission_Set[0].id, AssigneeId = userId);
[Link](NeoHelix_Accessioning_Permission_SetAssignment);
insert permissionSetList;
}
}
}

You might also like