Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AlsurOrderAssignment {
- public CPA_Order_Allocation__c allocation { get; set; }
- public List<CPA_Order_Allocation__c> currentAllocations { get; set; }
- public String association { get; set; }
- public String order {get; set;}
- public CPA_Order__c orderObject { get; set; }
- public Map<Id, CPA_Order__c> orderObjects { get; set; }
- public AlsurOrderAssignment() {
- allocation = new CPA_Order_Allocation__c(Number_of_Units_of_Presentation__c=0.00);
- orderObjects = new Map<Id, CPA_Order__c>();
- }
- public void findOrder() {
- System.debug(orderObjects.size());
- orderObject = orderObjects.get(order);System.debug('we got here');
- currentAllocations = [Select Id,
- Association__c,
- Association__r.Name,
- Number_of_Units_of_Presentation__c,
- Number_of_Kilos__c,
- Number_of_Baskets__c
- From
- CPA_Order_Allocation__c
- where
- CPA_Order__c=:order];
- }
- public List<SelectOption> getOrderItems() {
- List<CPA_Order__c> orders = [Select Id,
- Client__c,
- Product_Name__c,
- Unallocated_Units_of_Presentation__c,
- Unallocated_Number_of_Kilos__c,
- Unallocated_Number_of_Baskets__c,
- Client_Product_Association__c,
- Order_Code__c,
- Expected_Delivery_Date__c,
- Unit_of_Presentation__c,
- Presentacion__c
- from
- CPA_Order__c
- where
- Expected_Delivery_Date__c = LAST_N_DAYS:5
- and
- Unallocated_Units_of_Presentation__c > 0];
- orderObjects.putAll(orders);
- System.debug(orderObjects.size());
- List<SelectOption> options = new List<SelectOption>();
- for (CPA_Order__c order : orders) {
- options.add(new SelectOption(order.Id, order.Order_Code__c));
- }
- return options;
- }
- public PageReference saveAllocation() {
- allocation.CPA_Order__c = order;
- allocation.Association__c = association;
- insert allocation;
- PageReference currentPage = ApexPages.currentPage();
- currentPage.setRedirect(true);
- return currentPage;
- }
- public List<SelectOption> getAssociationItems() {
- list<Association__c> associations = [Select Id, Name from Association__c];
- List<SelectOption> options = new List<SelectOption>();
- for (Association__c association : associations) {
- options.add(new SelectOption(association.Id, association.Name));
- }
- return options;
- }
- }
- @isTest
- private class testAlsurOrderAssignment{
- @isTest
- static void validateAlsurOrderAssignment(){
- // 1. Set things up
- Association__c association = new Association__c();
- association.Name = 'Alsurtest';
- insert association;
- Contact contact = new Contact();
- contact.FirstName = 'pedrito';
- contact.LastName = 'perez';
- insert contact;
- CPA_Order__c order = new CPA_Order__c();
- order.Number_of_Units_of_Presentation__c = 10;
- order.Contact__c = contact.Id;
- order.Expected_Delivery_Date__c = System.today();
- order.Unit_of_Presentation__c = '5';
- insert order;
- CPA_Order_Allocation__c allocation = new CPA_Order_Allocation__c();
- allocation.CPA_Order__c = order.Id;
- allocation.Association__c = association.Id;
- allocation.Number_of_Units_of_Presentation__c = 5;
- allocation.Number_of_Kilos__c = 5;
- insert allocation;
- CPA_Order_Allocation__c[] allocations = [SELECT Id, CPA_Order__c from CPA_Order_Allocation__c where CPA_Order__c =: order.Id];
- System.assertEquals(allocations.size(), 1);
- // 2. Run the code you want to test
- // Run findOrder() method
- AlsurOrderAssignment assignmentClass = new AlsurOrderAssignment();
- assignmentClass.getOrderItems();
- System.assert(assignmentClass.orderObjects.size() > 0);
- List<SelectOption> options = assignmentClass.getAssociationItems();
- System.assert(options != null);
- assignmentClass.findOrder();
- System.assert(assignmentClass.orderObjects.size() > 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement