/**
|
* This class contains unit tests for validating the behavior of Apex classes
|
* and triggers.
|
*
|
* Unit tests are class methods that verify whether a particular piece
|
* of code is working properly. Unit test methods take no arguments,
|
* commit no data to the database, and are flagged with the testMethod
|
* keyword in the method definition.
|
*
|
* All test methods in an organization are executed whenever Apex code is deployed
|
* to a production organization to confirm correctness, ensure code
|
* coverage, and prevent regressions. All Apex classes are
|
* required to have at least 75% code coverage in order to be deployed
|
* to a production organization. In addition, all triggers must have some code coverage.
|
*
|
* The @isTest class annotation indicates this class only contains test
|
* methods. Classes defined with the @isTest annotation do not count against
|
* the organization size limit for all Apex scripts.
|
*
|
* See the Apex Language Reference for more information about Testing and Code Coverage.
|
*/
|
@isTest
|
private class SearchProductControllerTest {
|
|
static testMethod void myUnitTest() {
|
Product2 p2 = new Product2();
|
Apexpages.currentPage().getParameters().put('val', 'aaa');
|
Apexpages.Standardcontroller scon = new Apexpages.Standardcontroller(p2);
|
SearchProductController controller = new SearchProductController(scon);
|
controller.trade = 'CNY';
|
controller.serContact();
|
controller.trade = 'USD';
|
controller.serContact();
|
controller.trade = '';
|
controller.serContact();
|
|
}
|
|
static testMethod void initTest() {
|
Id pricebookId = ControllerUtil.getStandardPricebook().Id;
|
// 产品
|
Product2 pro1 = new Product2(
|
Name='name01',
|
IsActive=true,
|
Asset_Model_No__c='n01',
|
MDM_Model_No__c='n01',
|
ProductCode_Ext__c='pc01',
|
ProductCode = 'pc01',
|
Manual_Entry__c=false,
|
SFDA_Status__c='有効',
|
Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1),
|
Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1),
|
Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1),
|
Intra_Trade_List_RMB_1__c=100,
|
Intra_Trade_List_RMB_2__c=200,
|
Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1),
|
Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1),
|
Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1),
|
Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1),
|
Intra_Trade_Cost_RMB_1__c=10,
|
Intra_Trade_Cost_RMB_2__c=20
|
);
|
Product2 pro2 = new Product2(
|
Name='name02',
|
IsActive=true,
|
Asset_Model_No__c='n02',
|
MDM_Model_No__c='n02',
|
ProductCode_Ext__c='pc02',
|
ProductCode = 'pc02',
|
Manual_Entry__c=false,
|
SFDA_Status__c='有効',
|
Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1),
|
Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1),
|
Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1),
|
Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1),
|
Intra_Trade_List_RMB_1__c=100,
|
Intra_Trade_List_RMB_2__c=200,
|
Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1),
|
Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1),
|
Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1),
|
Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1),
|
Intra_Trade_Cost_RMB_1__c=10,
|
Intra_Trade_Cost_RMB_2__c=20
|
);
|
insert new Product2[] {pro1, pro2};
|
|
// 価格表エントリを作成する
|
PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=pro1.Id);
|
entry.UnitPrice = 0;
|
entry.IsActive = true;
|
entry.UseStandardPrice = false;
|
entry.CurrencyIsoCode = 'CNY';
|
PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=pro2.Id);
|
entry2.UnitPrice = 0;
|
entry2.IsActive = true;
|
entry2.UseStandardPrice = false;
|
entry2.CurrencyIsoCode = 'CNY';
|
|
insert new PricebookEntry[] {entry, entry2};
|
|
Apexpages.currentPage().getParameters().put('val', 'name');
|
Apexpages.Standardcontroller scon = new Apexpages.Standardcontroller(pro1);
|
SearchProductController controller = new SearchProductController(scon);
|
|
controller.getHascl();
|
|
controller.trade = 'CNY';
|
controller.serContact();
|
controller.trade = 'USD';
|
controller.serContact();
|
controller.trade = '';
|
controller.serContact();
|
|
controller.cl = new List<SearchProductController.ProductLine>();
|
controller.cl.add(new SearchProductController.ProductLine(0,entry));
|
|
}
|
|
}
|