Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class CM_LocationCaseListViewExt {
- private String accId = null;
- public transient String caseId {get;set;}
- private static final String APP = 'AlarmListView';
- private static final String CLASS_NAME = 'CM_LocationCaseListViewExt';
- public ApexPages.StandardSetController setCon {get;set;}
- /**
- * @description CM_LocationCaseListViewExt extension class constructor
- * @param NA
- * @return Setcon
- * @throws NA
- */
- public CM_LocationCaseListViewExt(ApexPages.StandardController controller) {
- accId = controller.getRecord().Id;
- }
- /**
- * @description This method queries the records and stores in standard set controller.
- * @param NA
- * @return NA
- * @throws NA
- */
- public void queryCases() {
- try {
- String queryString = 'SELECT CaseNumber,Owner.Name,Status,Subject,Problem_Description__c,WO_Number__c,CreatedDate,LastModifiedDate,isClosed,ClosedDate '+
- 'FROM Case WHERE AccountId =: accId AND RecordType.DeveloperName = 'FMOC' AND CreatedDate = LAST_N_DAYS:60 '+
- 'ORDER BY LastModifiedDate DESC NULLS LAST LIMIT 10000'; // a limit of 10000 is enforced since standard set controllers
- // can take a maximum of 10000 records
- setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
- setcon.setPageSize(25);
- }
- catch (Exception e) {UTIL_LoggingService.logHandledException(e,null,APP,CLASS_NAME,'queryCases',null,LoggingLevel.ERROR);}
- }
- /**
- * @description This is the wrapper class definition which will be used to bind the case object with a string which determines the age of the case
- */
- public class CaseWrapper {
- public Case caseObj {get;private set;}
- public String caseAge {get;private set;}
- }
- /**
- * @description This method binds the case object with a string 'Age' which determines the age of the case in number of days
- * @param NA
- * @return List<CaseWrapper>
- * @throws NA
- */
- public List<CaseWrapper> getCaseWrapperList() {
- // the list of case records are fetched
- List<Case> caseList = new List<Case>();
- if(setCon != null) {
- caseList = (List<Case>)setCon.getRecords();
- }
- List<CaseWrapper> listCaseWrapper = new List<CaseWrapper>();
- if(!caseList.isEmpty()) {
- for(Case cse: caseList) {
- CaseWrapper cw = new CaseWrapper();
- cw.caseObj = cse;
- // if the case is closed, age is determined by the number of days between the case creation date and the case closure date
- if(cse.isClosed) {
- cw.caseAge = String.valueOf(Date.ValueOf(cse.CreatedDate).daysBetween(Date.valueOf(cse.ClosedDate)));
- }
- // if the case is open, age is determined by the number of days between the case creation date and the current date
- else {
- cw.caseAge = String.valueOf(Date.ValueOf(cse.CreatedDate).daysBetween(System.TODAY()));
- }
- // the case record binding with the string takes place and is added to the case wrapper list
- listCaseWrapper.add(cw);
- }
- }
- return listCaseWrapper;
- }
- @isTest
- private class CM_LocationCaseListViewExtTest{
- static testMethod void testQueryCases() {
- //Inserting CustomSettings
- List<sObject> ls1 = Test.loadData(TargetGlobalMapping__c.sObjectType, 'Global_TargetGlobalMapping');
- List<sObject> ls2 = Test.loadData(Case_External_Links__c.sObjectType, 'Case_External_Links');
- // insert User related custom settings to account for security
- List<sObject> ls3 = Test.loadData(TargetGlobalMapping__c.sObjectType, 'UA_TEST_DATA_Tgt_global_mapping');
- List<sObject> ls4 = Test.loadData(User_Integration_Transformation_Table__c.sObjectType, 'UA_TEST_DATA_transformationtable');
- List<sObject> ls5 = Test.loadData(UserFeatureMappingTable__c.sObjectType, 'UA_TEST_DATA_FeatureMapping');
- // insert custom settings and ssf records used for alarm creation and association logic
- List<sObject> ls6 = Test.loadData(Simple_Support_Form__c.sObjectType, 'AlarmSimplesupportFormRecords');
- List<sObject> ls7 = Test.loadData(Alarm_Zones__c.sObjectType, 'Alarm_Zones');
- List<sObject> ls8 = Test.loadData(Alarm_Type_Mapping__c.sObjectType, 'AlarmTypeMapping');
- User admin = [SELECT id FROM User WHERE id =: UserInfo.getUserId() LIMIT 1];
- User adminUser;
- system.runAs(admin) {
- adminUser = WP_UtilTestData.createAdminUser();
- // populate Lan Id of the user
- adminUser.LAN_ID__c = 'A553881';
- Database.update(adminUser);
- }
- system.runAs(adminUser) {
- //creating account
- Account acc = new Account();
- acc = CM_UtilTestData.createAccount('T420 Testing');
- acc.Location_Alt_ID__c = 'T420';
- acc.Location_Id__c = '420';
- Database.insert(acc);
- Account a = [SELECT Id FROM Account WHERE id=:acc.id];
- Test.setCurrentPage(Page.CM_LocationCaseListView);
- ApexPages.StandardController stdController = new ApexPages.StandardController(acc);
- CM_LocationCaseListViewExt ext = new CM_LocationCaseListViewExt(stdController);
- String strRecordTypeId = [Select Id From RecordType Where SobjectType = 'Case' and Name = 'FMOC/STS'].Id;
- Test.startTest();
- //creating Cases
- Case cse1 = new Case();
- cse1 = CM_UtilTestData.createNewCase(a.Id,'New','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
- cse1.RecordTypeId = strRecordTypeId;
- Database.insert(cse1); //1st Case inserted
- Case cse2 = new Case();
- cse2 = CM_UtilTestData.createNewCase(a.Id,'In Progress','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
- cse2.RecordTypeId = strRecordTypeId;
- Database.insert(cse2); //2nd Case inserted
- Test.stopTest();
- ext.queryCases();
- ext.getCaseWrapperList();
- Case insertedCase1 = [SELECT CaseNumber,Status,RecordTypeId FROM Case WHERE id=:cse1.id];
- // Verify case creation
- System.assert(insertedCase1.CaseNumber!= null);
- //Verify case status
- System.assertEquals('New', insertedCase1.Status);
- //Verify record type
- System.assertEquals(strRecordTypeId, insertedCase1.RecordTypeId);
- Case insertedCase2 = [SELECT CaseNumber,Status,RecordTypeId,ClosedDate FROM Case WHERE id=:cse2.id];
- Verify case creation
- System.assert(insertedCase2.CaseNumber!= null);
- Verify case status
- System.assertEquals('In Progress', insertedCase2.Status);
- Verify record type
- System.assertEquals(strRecordTypeId, insertedCase2.RecordTypeId);
- changing status of 2nd Case
- insertedCase2.Status = 'Resolved';
- Database.update(insertedCase2);
- Case testCase = [SELECT ClosedDate,isClosed FROM Case WHERE id=:insertedCase2.id];
- System.assert(testCase.ClosedDate!= null);
- System.assertEquals(true,testCase.isClosed);
- }
- }
- }
- Test.startTest();
- //creating Cases
- Case cse1 = new Case();
- cse1 = CM_UtilTestData.createNewCase(a.Id,'New','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
- cse1.RecordTypeId = strRecordTypeId;
- Database.insert(cse1); //1st Case inserted
- Case cse2 = new Case();
- cse2 = CM_UtilTestData.createNewCase(a.Id,'In Progress','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
- cse2.RecordTypeId = strRecordTypeId;
- Database.insert(cse2); //2nd Case inserted
- ext.queryCases();
- ext.getCaseWrapperList();
- Case insertedCase1 = [SELECT CaseNumber,Status,RecordTypeId FROM Case WHERE id=:cse1.id];
- // Verify case creation
- System.assert(insertedCase1.CaseNumber!= null);
- //Verify case status
- System.assertEquals('New', insertedCase1.Status);
- //Verify record type
- System.assertEquals(strRecordTypeId, insertedCase1.RecordTypeId);
- Case insertedCase2 = [SELECT CaseNumber,Status,RecordTypeId,ClosedDate FROM Case WHERE id=:cse2.id];
- Verify case creation
- System.assert(insertedCase2.CaseNumber!= null);
- Verify case status
- System.assertEquals('In Progress', insertedCase2.Status);
- Verify record type
- System.assertEquals(strRecordTypeId, insertedCase2.RecordTypeId);
- changing status of 2nd Case
- insertedCase2.Status = 'Resolved';
- Database.update(insertedCase2);
- Case testCase = [SELECT ClosedDate,isClosed FROM Case WHERE id=:insertedCase2.id];
- System.assert(testCase.ClosedDate!= null);
- System.assertEquals(true,testCase.isClosed);
- ext.queryCases();
- ext.getCaseWrapperList();
- Test.stopTest();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement