@isTest private class SearchProductControllerTest { @isTest static void test_init1() { 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'; product1.ProductModels__c = true; product1.ProductStatus__c = '1'; product1.MaterialStatus_one_Start__c = Date.today().addDays(-22); product1.MaterialStatus_one_End__c = Date.today().addDays(22); product1.NMPAStatus_one__c = 'Z1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; insert entry1; Product_Search__c ps = new Product_Search__c(Product__c = product1.Id); List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE']; Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectIE[0].Id ); insert user; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Prospect Created', 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', Pricebook2Id = pricebook.Id ); insert opp; PageReference page = new PageReference('/apex/SearchProduct?oppId=' + opp.Id + '&val=product1'); System.Test.setCurrentPage(page); SearchProductController controller = new SearchProductController(); controller.init(); controller.getHascl(); } @isTest static void test_init2() { NewReplacementOpportunityController.a(); 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'; product1.ProductModels__c = true; product1.ProductStatus__c = '1'; product1.MaterialStatus_one_Start__c = Date.today().addDays(-22); product1.MaterialStatus_one_End__c = Date.today().addDays(22); product1.NMPAStatus_one__c = 'Z1'; insert product1; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, IsActive = true ); insert standardPrice1; PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; insert entry1; Product_Search__c ps = new Product_Search__c(Product__c = product1.Id); List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE']; Account user = new Account( Name = '*', FacilityName__c = 'user', PostCode__c = '123456', RecordTypeId = rectIE[0].Id ); insert user; Opportunity opp = new Opportunity( Name = 'test opp', AccountId = user.Id, StageName = 'Prospect Created', 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', Pricebook2Id = pricebook.Id ); insert opp; PageReference page = new PageReference('/apex/SearchProduct?oppId=' + opp.Id + '&val=product1&openType=service&openFlag=opp'); System.Test.setCurrentPage(page); SearchProductController controller = new SearchProductController(); controller.init(); controller.getHascl(); } }