Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. public with sharing class CM_LocationCaseListViewExt {
  2. private String accId = null;
  3. public transient String caseId {get;set;}
  4.  
  5. private static final String APP = 'AlarmListView';
  6. private static final String CLASS_NAME = 'CM_LocationCaseListViewExt';
  7.  
  8. public ApexPages.StandardSetController setCon {get;set;}
  9.  
  10. /**
  11. * @description CM_LocationCaseListViewExt extension class constructor
  12. * @param NA
  13. * @return Setcon
  14. * @throws NA
  15. */
  16. public CM_LocationCaseListViewExt(ApexPages.StandardController controller) {
  17.  
  18. accId = controller.getRecord().Id;
  19. }
  20.  
  21. /**
  22. * @description This method queries the records and stores in standard set controller.
  23. * @param NA
  24. * @return NA
  25. * @throws NA
  26. */
  27. public void queryCases() {
  28. try {
  29. String queryString = 'SELECT CaseNumber,Owner.Name,Status,Subject,Problem_Description__c,WO_Number__c,CreatedDate,LastModifiedDate,isClosed,ClosedDate '+
  30. 'FROM Case WHERE AccountId =: accId AND RecordType.DeveloperName = 'FMOC' AND CreatedDate = LAST_N_DAYS:60 '+
  31. 'ORDER BY LastModifiedDate DESC NULLS LAST LIMIT 10000'; // a limit of 10000 is enforced since standard set controllers
  32. // can take a maximum of 10000 records
  33.  
  34. setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
  35. setcon.setPageSize(25);
  36. }
  37. catch (Exception e) {UTIL_LoggingService.logHandledException(e,null,APP,CLASS_NAME,'queryCases',null,LoggingLevel.ERROR);}
  38. }
  39.  
  40.  
  41.  
  42. /**
  43. * @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
  44. */
  45. public class CaseWrapper {
  46. public Case caseObj {get;private set;}
  47. public String caseAge {get;private set;}
  48. }
  49.  
  50. /**
  51. * @description This method binds the case object with a string 'Age' which determines the age of the case in number of days
  52. * @param NA
  53. * @return List<CaseWrapper>
  54. * @throws NA
  55. */
  56. public List<CaseWrapper> getCaseWrapperList() {
  57.  
  58. // the list of case records are fetched
  59. List<Case> caseList = new List<Case>();
  60. if(setCon != null) {
  61. caseList = (List<Case>)setCon.getRecords();
  62. }
  63.  
  64. List<CaseWrapper> listCaseWrapper = new List<CaseWrapper>();
  65.  
  66. if(!caseList.isEmpty()) {
  67.  
  68. for(Case cse: caseList) {
  69. CaseWrapper cw = new CaseWrapper();
  70.  
  71. cw.caseObj = cse;
  72. // if the case is closed, age is determined by the number of days between the case creation date and the case closure date
  73. if(cse.isClosed) {
  74. cw.caseAge = String.valueOf(Date.ValueOf(cse.CreatedDate).daysBetween(Date.valueOf(cse.ClosedDate)));
  75. }
  76. // if the case is open, age is determined by the number of days between the case creation date and the current date
  77. else {
  78. cw.caseAge = String.valueOf(Date.ValueOf(cse.CreatedDate).daysBetween(System.TODAY()));
  79. }
  80.  
  81. // the case record binding with the string takes place and is added to the case wrapper list
  82. listCaseWrapper.add(cw);
  83. }
  84. }
  85.  
  86. return listCaseWrapper;
  87. }
  88.  
  89. @isTest
  90. private class CM_LocationCaseListViewExtTest{
  91. static testMethod void testQueryCases() {
  92. //Inserting CustomSettings
  93. List<sObject> ls1 = Test.loadData(TargetGlobalMapping__c.sObjectType, 'Global_TargetGlobalMapping');
  94. List<sObject> ls2 = Test.loadData(Case_External_Links__c.sObjectType, 'Case_External_Links');
  95.  
  96. // insert User related custom settings to account for security
  97. List<sObject> ls3 = Test.loadData(TargetGlobalMapping__c.sObjectType, 'UA_TEST_DATA_Tgt_global_mapping');
  98. List<sObject> ls4 = Test.loadData(User_Integration_Transformation_Table__c.sObjectType, 'UA_TEST_DATA_transformationtable');
  99. List<sObject> ls5 = Test.loadData(UserFeatureMappingTable__c.sObjectType, 'UA_TEST_DATA_FeatureMapping');
  100.  
  101. // insert custom settings and ssf records used for alarm creation and association logic
  102. List<sObject> ls6 = Test.loadData(Simple_Support_Form__c.sObjectType, 'AlarmSimplesupportFormRecords');
  103. List<sObject> ls7 = Test.loadData(Alarm_Zones__c.sObjectType, 'Alarm_Zones');
  104. List<sObject> ls8 = Test.loadData(Alarm_Type_Mapping__c.sObjectType, 'AlarmTypeMapping');
  105.  
  106. User admin = [SELECT id FROM User WHERE id =: UserInfo.getUserId() LIMIT 1];
  107. User adminUser;
  108.  
  109. system.runAs(admin) {
  110. adminUser = WP_UtilTestData.createAdminUser();
  111. // populate Lan Id of the user
  112. adminUser.LAN_ID__c = 'A553881';
  113. Database.update(adminUser);
  114. }
  115.  
  116. system.runAs(adminUser) {
  117.  
  118. //creating account
  119. Account acc = new Account();
  120.  
  121. acc = CM_UtilTestData.createAccount('T420 Testing');
  122. acc.Location_Alt_ID__c = 'T420';
  123. acc.Location_Id__c = '420';
  124. Database.insert(acc);
  125.  
  126. Account a = [SELECT Id FROM Account WHERE id=:acc.id];
  127.  
  128. Test.setCurrentPage(Page.CM_LocationCaseListView);
  129. ApexPages.StandardController stdController = new ApexPages.StandardController(acc);
  130. CM_LocationCaseListViewExt ext = new CM_LocationCaseListViewExt(stdController);
  131.  
  132. String strRecordTypeId = [Select Id From RecordType Where SobjectType = 'Case' and Name = 'FMOC/STS'].Id;
  133.  
  134. Test.startTest();
  135. //creating Cases
  136. Case cse1 = new Case();
  137. cse1 = CM_UtilTestData.createNewCase(a.Id,'New','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
  138. cse1.RecordTypeId = strRecordTypeId;
  139. Database.insert(cse1); //1st Case inserted
  140.  
  141. Case cse2 = new Case();
  142. cse2 = CM_UtilTestData.createNewCase(a.Id,'In Progress','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
  143. cse2.RecordTypeId = strRecordTypeId;
  144. Database.insert(cse2); //2nd Case inserted
  145. Test.stopTest();
  146.  
  147. ext.queryCases();
  148. ext.getCaseWrapperList();
  149.  
  150. Case insertedCase1 = [SELECT CaseNumber,Status,RecordTypeId FROM Case WHERE id=:cse1.id];
  151. // Verify case creation
  152. System.assert(insertedCase1.CaseNumber!= null);
  153. //Verify case status
  154. System.assertEquals('New', insertedCase1.Status);
  155. //Verify record type
  156. System.assertEquals(strRecordTypeId, insertedCase1.RecordTypeId);
  157.  
  158. Case insertedCase2 = [SELECT CaseNumber,Status,RecordTypeId,ClosedDate FROM Case WHERE id=:cse2.id];
  159. Verify case creation
  160. System.assert(insertedCase2.CaseNumber!= null);
  161. Verify case status
  162. System.assertEquals('In Progress', insertedCase2.Status);
  163. Verify record type
  164. System.assertEquals(strRecordTypeId, insertedCase2.RecordTypeId);
  165. changing status of 2nd Case
  166. insertedCase2.Status = 'Resolved';
  167.  
  168. Database.update(insertedCase2);
  169.  
  170. Case testCase = [SELECT ClosedDate,isClosed FROM Case WHERE id=:insertedCase2.id];
  171. System.assert(testCase.ClosedDate!= null);
  172. System.assertEquals(true,testCase.isClosed);
  173.  
  174.  
  175. }
  176. }
  177.  
  178.  
  179. }
  180.  
  181. Test.startTest();
  182. //creating Cases
  183. Case cse1 = new Case();
  184. cse1 = CM_UtilTestData.createNewCase(a.Id,'New','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
  185. cse1.RecordTypeId = strRecordTypeId;
  186. Database.insert(cse1); //1st Case inserted
  187.  
  188. Case cse2 = new Case();
  189. cse2 = CM_UtilTestData.createNewCase(a.Id,'In Progress','Alarm',null,'FMOC Only','Refrigeration Alarm','REF LEAK',null,null,null);
  190. cse2.RecordTypeId = strRecordTypeId;
  191. Database.insert(cse2); //2nd Case inserted
  192.  
  193. ext.queryCases();
  194. ext.getCaseWrapperList();
  195.  
  196. Case insertedCase1 = [SELECT CaseNumber,Status,RecordTypeId FROM Case WHERE id=:cse1.id];
  197. // Verify case creation
  198. System.assert(insertedCase1.CaseNumber!= null);
  199. //Verify case status
  200. System.assertEquals('New', insertedCase1.Status);
  201. //Verify record type
  202. System.assertEquals(strRecordTypeId, insertedCase1.RecordTypeId);
  203.  
  204. Case insertedCase2 = [SELECT CaseNumber,Status,RecordTypeId,ClosedDate FROM Case WHERE id=:cse2.id];
  205. Verify case creation
  206. System.assert(insertedCase2.CaseNumber!= null);
  207. Verify case status
  208. System.assertEquals('In Progress', insertedCase2.Status);
  209. Verify record type
  210. System.assertEquals(strRecordTypeId, insertedCase2.RecordTypeId);
  211. changing status of 2nd Case
  212. insertedCase2.Status = 'Resolved';
  213.  
  214. Database.update(insertedCase2);
  215.  
  216. Case testCase = [SELECT ClosedDate,isClosed FROM Case WHERE id=:insertedCase2.id];
  217. System.assert(testCase.ClosedDate!= null);
  218. System.assertEquals(true,testCase.isClosed);
  219. ext.queryCases();
  220. ext.getCaseWrapperList();
  221. Test.stopTest();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement