Guest User

Untitled

a guest
Apr 17th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. User currentUser = [SELECT contactId FROM User WHERE Id = :UserInfo.getUserId()];
  2. System.debug('Current user' + currentUser);
  3. //Fetch the current contact object
  4. if(String.isNotBlank(currentUser.ContactId)) {
  5.  
  6. contact = [
  7. SELECT AccountId, firstName, lastName, MiddleName, Nickname__c, Suffix, MailingStreet, MailingCity,
  8. MailingStateCode, Certify_Complete_and_Correct__c, Certify_Download_Instructions_to_PreCan__c
  9. FROM Contact
  10. WHERE Id = :currentUser.ContactId
  11. LIMIT 1
  12. ];
  13.  
  14. System.debug('contact information: ' + contact );
  15.  
  16. //Fetch the current application object
  17. application = [
  18.  
  19. SELECT Id, Contact__c, Attend_College_after_High_School__c
  20. FROM Application__c
  21. WHERE Contact__c =: currentUser.contactId
  22. LIMIT 1];
  23.  
  24.  
  25. }
  26.  
  27. }
  28.  
  29. And the following submit method in the apex class
  30.  
  31. public pagereference submit() {
  32.  
  33. if (
  34. contact.Certify_Complete_and_Correct__c == false ||
  35. contact.Certify_Download_Instructions_to_PreCan__c == false
  36.  
  37. )
  38.  
  39. {
  40. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please make sure all required fields are populated.');
  41. ApexPages.addMessage(myMsg);
  42. return null;
  43. }
  44.  
  45.  
  46.  
  47. // ALO Code
  48.  
  49.  
  50. if(application.Attend_College_after_High_School__c == 'No')
  51.  
  52. {
  53.  
  54. acc = [
  55.  
  56. SELECT Id, OwnerId
  57. FROM Account
  58. WHERE Id =: contact.AccountId
  59. ];
  60.  
  61.  
  62. contact.ALO__c = acc.OwnerId;
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. else if(application.Attend_College_after_High_School__c == 'Yes')
  70.  
  71. {
  72.  
  73.  
  74.  
  75. ziptoLOD = [
  76.  
  77. SELECT Id, Name, LOD__c
  78. FROM Zip_3_to_LOD__c
  79. WHERE Name =: contact.Extract_Zipcode__c
  80.  
  81. ];
  82.  
  83.  
  84.  
  85. contact.ALO__c = ziptoLOD.LOD__c;
  86.  
  87.  
  88. }
  89.  
  90. static testMethod void submit_Test() {
  91.  
  92. Profile AdminProfile = [select id from profile where name='System Administrator'];
  93. UserRole AdminRole = [SELECT id from UserRole where name = 'Admin'];
  94.  
  95.  
  96. User currentuser = new User();
  97. currentuser.firstname ='James';
  98. currentuser.lastname ='Dobb';
  99. currentuser.email ='[email protected]';
  100. currentuser.username ='[email protected]';
  101. currentuser.alias ='jdobb';
  102. currentuser.TimeZoneSidKey ='GMT';
  103. currentuser.LocaleSidKey ='en_US';
  104. currentuser.emailencodingkey ='UTF-8';
  105. currentuser.languagelocalekey ='en_US';
  106. currentuser.ProfileId = AdminProfile.Id;
  107. currentuser.userroleid = AdminRole.Id;
  108. insert currentuser;
  109.  
  110.  
  111. Account acc= new Account();
  112. acc.OwnerId='005r0000001i9xA';
  113. acc.Name='Atlanta Area Tech School';
  114. acc.RecordTypeId='012r00000005DsA';
  115.  
  116.  
  117. Zip_3_to_LOD__c zip= new Zip_3_to_LOD__c();
  118. zip.Name = '480';
  119. zip.LOD__c = '005t0000001LDpi';
  120.  
  121. Contact contact = new Contact();
  122. contact.firstName = 'Alex';
  123. contact.lastName = 'Cauller';
  124. contact.email = '[email protected]';
  125. contact.AccountId = acc.Id;
  126.  
  127.  
  128.  
  129. system.runas(currentuser){
  130. insert acc;
  131. insert contact;
  132. insert zip;
  133.  
  134.  
  135. }
  136.  
  137.  
  138.  
  139. Application__c app= new Application__c();
  140. app.Contact__c = contact.Id;
  141. app.Attend_College_after_High_School__c= 'No';
  142.  
  143.  
  144. system.runas(currentuser){
  145.  
  146. insert app;
  147. }
  148.  
  149. Profile pr = [select id from profile where name='......'];
  150. User u = new User();
  151. u.firstname ='James';
  152. u.lastname ='Dobb';
  153. u.email ='[email protected]';
  154. u.username ='[email protected]';
  155. u.alias ='jdobb';
  156. u.TimeZoneSidKey ='GMT';
  157. u.LocaleSidKey ='en_US';
  158. u.emailencodingkey ='UTF-8';
  159. u.languagelocalekey ='en_US';
  160. u.ProfileId = pr.Id;
  161. u.contactId =contact.id;
  162. insert u;
  163.  
  164. system.runAs(u){
  165. System.Test.startTest();
  166. Page4Controller controllerClass = new Page4Controller();
  167. controllerClass.contact.Certify_Complete_and_Correct__c = false;
  168. controllerClass.contact.Certify_Download_Instructions_to_PreCan__c = false;
  169. controllerClass.submit();
  170. System.AssertEquals(controllerClass.contact.ALO__c,acc.OwnerId);
  171. controllerClass.application.Attend_College_after_High_School__c = 'Yes';
  172. controllerClass.submit();
  173. System.AssertEquals(controllerClass.contact.ALO__c,zip.LOD__c);
  174. controllerClass.previouspage();
  175. System.Test.stopTest();
  176.  
  177.  
  178. }
  179.  
  180.  
  181. When I run the test case, the test case fails and generates the following error on both the assert statements
  182.  
  183. System.AssertException: Assertion Failed: Expected: null, Actual: 005r0000001i9xAAAQ
  184.  
  185. }
Add Comment
Please, Sign In to add comment