@isTest private class OrderPdf2ControllerTest { @isTest static void test_init1() { OrderPdf2Controller.asd(); List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'IE' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectIE[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'IE', ProductSegment__c = 'IE', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'IE', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', Dealer__c = buyer.Id, SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, Role = 'End user', IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', CurrencyIsoCode = 'CNY', AccountId = user.Id, OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id //ProductListApproveStatus__c = 'Reject' ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderPdf2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init(); /* oiList = new List(); for (Integer i = 0; i < 10; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; controller.init(); oiList = new List(); for (Integer i = 0; i < 48; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; controller.init();*/ } @isTest static void test_init2() { List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'IE' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectIE[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'IE', ProductSegment__c = 'IE', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; Product2 product2 = new Product2(); product2.Name = 'product2'; product2.ProductCode = 'product2'; product2.Product_ECCode__c = 'product165456456465'; insert product2; Product2 product3 = new Product2(); product3.Name = 'product3'; product3.ProductCode = 'product3'; product3.Product_ECCode__c = 'product16545645641265'; insert product3; Product2 product4 = new Product2(); product4.Name = 'product4'; product4.ProductCode = 'product4'; product4.Product_ECCode__c = 'product165456asd5641265'; insert product4; Product2 product5 = new Product2(); product5.Name = 'product5'; product5.ProductCode = 'product5'; product5.Product_ECCode__c = 'product16512456asd5641265'; insert product5; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'IE', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', Dealer__c = buyer.Id, SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', AccountId = user.Id, CurrencyIsoCode = 'CNY', OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderContract2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init2(); controller.inputDetails[0].factory = 'factory0'; controller.saveBtn(); List oiList1 = [select id, Factory__c from OrderItem where OrderId = :order.Id]; System.assertEquals('factory0', oiList1[0].Factory__c); controller.printBtn(); } @isTest static void test_init3() { List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'BS' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectBS[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'BS', ProductSegment__c = 'BS', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'BS', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, Role = 'End user', IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', CurrencyIsoCode = 'CNY', AccountId = user.Id, OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id //ProductListApproveStatus__c = 'Reject' ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderPdf2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init(); } @isTest static void test_init4() { List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectBS = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'BS' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectBS[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'BS', ProductSegment__c = 'BS', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'BS', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', AccountId = user.Id, CurrencyIsoCode = 'CNY', OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderContract2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init2(); controller.inputDetails[0].factory = 'factory0'; controller.saveBtn(); List oiList1 = [select id, Factory__c from OrderItem where OrderId = :order.Id]; System.assertEquals('factory0', oiList1[0].Factory__c); controller.printBtn(); } @isTest static void test_init5() { List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectNDT = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer NDT']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'NDT' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectNDT[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'NDT', ProductSegment__c = 'NDT', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'NDT', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', Dealer__c = buyer.Id, SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, Role = 'End user', IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', CurrencyIsoCode = 'CNY', AccountId = user.Id, OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id //ProductListApproveStatus__c = 'Reject' ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderPdf2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init(); } @isTest static void test_init6() { List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; List rectNDT = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer NDT']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'NDT' ); Account delivery = new Account( Name = '*', FacilityName__c = 'delivery', PostCode__c = '123456' ); Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectNDT[0].Id ); insert new List {buyer, delivery, user}; Contact delivery_contact = new Contact( LastName = 'delivery_contact', AccountId = delivery.Id ); Contact contact = new Contact( LastName = 'contact', AccountId = user.Id ); insert new List {delivery_contact, contact}; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'NDT', ProductSegment__c = 'NDT', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.ProductCode = 'product1'; product1.Product_ECCode__c = 'product1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, CurrencyIsoCode = 'CNY', IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; insert entry1; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Phase3', CurrencyIsoCode = 'CNY', ProductSegment__c = 'NDT', CloseDate = Date.today(), NewInquiryDate__c = Date.today().addDays(-2), ExpectedOrderDate__c = Date.today().addDays(2), TradeType__c = 'Taxation', SalesChannel__c = 'direct', Machine_Parts__c = 'Machine', Dealer__c = buyer.Id, SpecialDeliveryAddress__c = delivery.Id, SpecialDeliveryContact__c = delivery_contact.Id, Pricebook2Id = pricebook.Id ); insert opp; OpportunityContactRole ocr = new OpportunityContactRole( OpportunityId = opp.Id, ContactId = contact.Id, IsPrimary = true ); insert ocr; Order order = new Order( Name = 'order', AccountId = user.Id, CurrencyIsoCode = 'CNY', OpportunityId = opp.Id, EffectiveDate = Date.today(), Status = 'Draft', Pricebook2Id = pricebook.Id, EndUser__c = contact.Id, EndUserD__c = contact.Id ); insert order; List oiList = new List(); for (Integer i = 0; i < 1; i++) { OrderItem oi = new OrderItem( OrderId = order.Id, PriceBookEntryId = entry1.Id, Quantity = 1, UnitPrice = 10 ); oiList.add(oi); } insert oiList; PageReference page = new PageReference('/apex/OrderContract2?id=' + order.Id); System.Test.setCurrentPage(page); OrderPdf2Controller controller = new OrderPdf2Controller(); controller.init2(); controller.inputDetails[0].factory = 'factory0'; controller.saveBtn(); List oiList1 = [select id, Factory__c from OrderItem where OrderId = :order.Id]; System.assertEquals('factory0', oiList1[0].Factory__c); controller.printBtn(); } }