liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
 * 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 NewQuoteEntryWebServiceTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static testMethod void myUnitTest() {
        NewQuoteEntryWebService.getProduct2(new List<String>());
        NewQuoteEntryWebService.getQuoteLineItem('12345');
    }
    
    static testMethod void selectQuotationTest() {
        
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        insert product;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
        
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='contact';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        insert opp;
        
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '111';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        
        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        insert qli;
        
        Opportunity[] opp1 = [select Estimation_List_Price__c,Wholesale_Price__c,Dealer_Final_Price__c,OCM_Agent1_Price__c,
                                      Stocking_Price__c,Estimation_No__c,Estimation_Name__c,Estimation_Id__c
                                from Opportunity where id = :opp.Id];
        System.assertEquals(100, opp1[0].Estimation_List_Price__c);
        System.assertEquals(101, opp1[0].Wholesale_Price__c);
        System.assertEquals(102, opp1[0].Dealer_Final_Price__c);
        System.assertEquals(103, opp1[0].OCM_Agent1_Price__c);
        System.assertEquals(104, opp1[0].Stocking_Price__c);
        System.assertEquals('105', opp1[0].Estimation_No__c);
        System.assertEquals('106', opp1[0].Estimation_Name__c);
        System.assertEquals('107', opp1[0].Estimation_Id__c);
        
        OpportunityLineItem[] oppli1 = [select Id__c,SFDA_Status__c,Name__c,ListPrice__c,Quantity,UnitPrice,UnitPrice__c,Qty_Unit__c,
                                             Cost__c,BSS_Category__c,Item_Order__c
                                        from OpportunityLineItem where OpportunityId = :opp.Id];
        System.assertEquals('110', oppli1[0].Id__c);
        System.assertEquals('有効', oppli1[0].SFDA_Status__c);
        System.assertEquals('111', oppli1[0].Name__c);
        System.assertEquals(112, oppli1[0].ListPrice__c);
        System.assertEquals(113, oppli1[0].Quantity);
        System.assertEquals(114, oppli1[0].UnitPrice);
        System.assertEquals(115, oppli1[0].UnitPrice__c);
        System.assertEquals('116', oppli1[0].Qty_Unit__c);
        System.assertEquals(117, oppli1[0].Cost__c);
        System.assertEquals('G&R', oppli1[0].BSS_Category__c);
        System.assertEquals(1, oppli1[0].Item_Order__c);
 
        PowerBISyncDefine__c olPowerBISyncDefine = new PowerBISyncDefine__c();
        olPowerBISyncDefine.Name = 'OpportunityLineItem';
        olPowerBISyncDefine.To_Table__c = 'BI_OpportunityLineItem__c';
        upsert olPowerBISyncDefine;
 
        NewQuoteEntryWebService.selectQuotation(opp.Id, quo.Id);
        
        Opportunity[] opp2 = [select Estimation_List_Price__c,Wholesale_Price__c,Dealer_Final_Price__c,OCM_Agent1_Price__c,
                                      Stocking_Price__c,Estimation_No__c,Estimation_Name__c,Estimation_Id__c
                                from Opportunity where id = :opp.Id];
        System.assertEquals(200, opp2[0].Estimation_List_Price__c);
        System.assertEquals(201, opp2[0].Wholesale_Price__c);
        System.assertEquals(202, opp2[0].Dealer_Final_Price__c);
        System.assertEquals(203, opp2[0].OCM_Agent1_Price__c);
        System.assertEquals(204, opp2[0].Stocking_Price__c);
        System.assertEquals('205', opp2[0].Estimation_No__c);
        System.assertEquals('206', opp2[0].Estimation_Name__c);
        System.assertEquals(quo.Id, opp2[0].Estimation_Id__c);
        
        OpportunityLineItem[] oppli2 = [select Id__c,SFDA_Status__c,Name__c,ListPrice__c,Quantity,UnitPrice,UnitPrice__c,Qty_Unit__c,
                                             Cost__c,BSS_Category__c,Item_Order__c
                                        from OpportunityLineItem where OpportunityId = :opp.Id];
        System.assertEquals('210', oppli2[0].Id__c);
        System.assertEquals('有効', oppli2[0].SFDA_Status__c);
        System.assertEquals('211', oppli2[0].Name__c);
        System.assertEquals(212, oppli2[0].ListPrice__c);
        System.assertEquals(213, oppli2[0].Quantity);
        System.assertEquals(0, oppli2[0].UnitPrice);
        System.assertEquals(215, oppli2[0].UnitPrice__c);
        System.assertEquals('216', oppli2[0].Qty_Unit__c);
        System.assertEquals(217, oppli2[0].Cost__c);
        System.assertEquals('ET', oppli2[0].BSS_Category__c);
        System.assertEquals(1, oppli2[0].Item_Order__c);
    }
 
    static testMethod void selectQuotationTest2() {
        
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '停止';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        insert product;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
 
        Product2 product1 = new Product2( Name='テスト商品');
        product1.SFDA_Status__c = '有効';
        product1.Intra_Trade_List_RMB_1__c = 100;
        product1.Intra_Trade_List_RMB_Date1__c = date.today();
        product1.Intra_Trade_Cost_RMB_1__c = 200;
        product1.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '111112';
        product1.ProductCode = 'OTV-SP1H-NA-13E';
        insert product1;
        
        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id=pricebookId,Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        insert entry1;
 
        
        Opportunity opp = new Opportunity();
        opp.Name='aiueo';
        opp.StageName='contact';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        insert opp;
        
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '111';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        
        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        insert qli;
 
        NewQuoteEntryWebService.updateOTCode( quo.Id);
        
 
    }
 
 
}