Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. public class AlsurOrderAssignment {
  2.  
  3. public CPA_Order_Allocation__c allocation { get; set; }
  4. public List<CPA_Order_Allocation__c> currentAllocations { get; set; }
  5. public String association { get; set; }
  6. public String order {get; set;}
  7. public CPA_Order__c orderObject { get; set; }
  8. public Map<Id, CPA_Order__c> orderObjects { get; set; }
  9.  
  10. public AlsurOrderAssignment() {
  11. allocation = new CPA_Order_Allocation__c(Number_of_Units_of_Presentation__c=0.00);
  12. orderObjects = new Map<Id, CPA_Order__c>();
  13. }
  14. public void findOrder() {
  15. System.debug(orderObjects.size());
  16. orderObject = orderObjects.get(order);System.debug('we got here');
  17. currentAllocations = [Select Id,
  18. Association__c,
  19. Association__r.Name,
  20. Number_of_Units_of_Presentation__c,
  21. Number_of_Kilos__c,
  22. Number_of_Baskets__c
  23. From
  24. CPA_Order_Allocation__c
  25. where
  26. CPA_Order__c=:order];
  27. }
  28.  
  29. public List<SelectOption> getOrderItems() {
  30.  
  31. List<CPA_Order__c> orders = [Select Id,
  32. Client__c,
  33. Product_Name__c,
  34. Unallocated_Units_of_Presentation__c,
  35. Unallocated_Number_of_Kilos__c,
  36. Unallocated_Number_of_Baskets__c,
  37. Client_Product_Association__c,
  38. Order_Code__c,
  39. Expected_Delivery_Date__c,
  40. Unit_of_Presentation__c,
  41. Presentacion__c
  42. from
  43. CPA_Order__c
  44. where
  45. Expected_Delivery_Date__c = LAST_N_DAYS:5
  46. and
  47. Unallocated_Units_of_Presentation__c > 0];
  48.  
  49. orderObjects.putAll(orders);
  50. System.debug(orderObjects.size());
  51. List<SelectOption> options = new List<SelectOption>();
  52. for (CPA_Order__c order : orders) {
  53. options.add(new SelectOption(order.Id, order.Order_Code__c));
  54. }
  55. return options;
  56. }
  57.  
  58. public PageReference saveAllocation() {
  59. allocation.CPA_Order__c = order;
  60. allocation.Association__c = association;
  61. insert allocation;
  62. PageReference currentPage = ApexPages.currentPage();
  63. currentPage.setRedirect(true);
  64. return currentPage;
  65. }
  66. public List<SelectOption> getAssociationItems() {
  67. list<Association__c> associations = [Select Id, Name from Association__c];
  68. List<SelectOption> options = new List<SelectOption>();
  69. for (Association__c association : associations) {
  70. options.add(new SelectOption(association.Id, association.Name));
  71. }
  72. return options;
  73. }
  74. }
  75.  
  76. @isTest
  77. private class testAlsurOrderAssignment{
  78. @isTest
  79. static void validateAlsurOrderAssignment(){
  80. // 1. Set things up
  81. Association__c association = new Association__c();
  82. association.Name = 'Alsurtest';
  83. insert association;
  84.  
  85. Contact contact = new Contact();
  86. contact.FirstName = 'pedrito';
  87. contact.LastName = 'perez';
  88. insert contact;
  89.  
  90. CPA_Order__c order = new CPA_Order__c();
  91. order.Number_of_Units_of_Presentation__c = 10;
  92. order.Contact__c = contact.Id;
  93. order.Expected_Delivery_Date__c = System.today();
  94. order.Unit_of_Presentation__c = '5';
  95. insert order;
  96.  
  97. CPA_Order_Allocation__c allocation = new CPA_Order_Allocation__c();
  98. allocation.CPA_Order__c = order.Id;
  99. allocation.Association__c = association.Id;
  100. allocation.Number_of_Units_of_Presentation__c = 5;
  101. allocation.Number_of_Kilos__c = 5;
  102. insert allocation;
  103.  
  104. CPA_Order_Allocation__c[] allocations = [SELECT Id, CPA_Order__c from CPA_Order_Allocation__c where CPA_Order__c =: order.Id];
  105. System.assertEquals(allocations.size(), 1);
  106.  
  107. // 2. Run the code you want to test
  108. // Run findOrder() method
  109. AlsurOrderAssignment assignmentClass = new AlsurOrderAssignment();
  110.  
  111. assignmentClass.getOrderItems();
  112. System.assert(assignmentClass.orderObjects.size() > 0);
  113.  
  114. List<SelectOption> options = assignmentClass.getAssociationItems();
  115. System.assert(options != null);
  116.  
  117. assignmentClass.findOrder();
  118. System.assert(assignmentClass.orderObjects.size() > 0);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement