高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
@isTest
private class NFM117RestTest {
    static testMethod void testMethod1() {
        // テストデータ
        List<BatchIF_Transfer__c> transfers = new List<BatchIF_Transfer__c>();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '0';
        transfer.Internal_Value__c = '無';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Repair__c';
        transfer.Column__c         = 'With_Maintenance_Contract__c';
        transfer.External_Value__c = '1';
        transfer.Internal_Value__c = '有';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM117TestCompany';
        upsert company;
        Account section = new Account();
        section.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
 
        StaticParameter.EscapeSyncProduct2Trigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM117TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        
        
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM117Prd1';
        prd1.ProductCode            = 'NFM117Prd1';
        prd1.Repair_Product_Code__c = 'NFM117Prd1_RP';
        prd1.Name                   = 'NFM117Prd1';
        prd1.Manual_Entry__c        = false;
        prd1.CanRepairAccsessary__c = true;
        prdList.add(prd1);
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'NFM117Prd2';
        prd2.ProductCode            = 'NFM117Prd2';
        prd2.Repair_Product_Code__c = 'NFM117Prd2_RP';
        prd2.Name                   = 'NFM117Prd2';
        prd2.Manual_Entry__c        = false;
        prd2.CanRepairAccsessary__c = true;
        prdList.add(prd2);
        insert prdList;
 
 
        Asset ast = new Asset();
        ast.Name                   = 'NFM117Ast1';
        ast.AccountId              = depart.Id;
        ast.Department_Class__c    = section.Id;
        ast.Hospital__c            = company.Id;
        ast.Product2Id             = prd1.Id;
        ast.Quantity               = 100;
        ast.SerialNumber           = 'NFM117SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        
        insert ast;
        ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber 
                                 from Asset
                                where Id = :ast.Id];
 
        Repair__c rpr = new Repair__c();
        rpr.Incharge_Staff__c = Userinfo.getUserId();
        rpr.Status__c = '1.受理完毕';
        rpr.SAPRepairNo__c   = 'NFM117Repair1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.work_location_select__c = '北京办事处';
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Repair_Detail__c = 'test';
        rpr.Returns_Product_way__c = '返送医院';
        rpr.FSE_ApplyForRepair_time__c = Date.today();
        insert rpr;
        Repair__c rpr2 = [Select Id, SAPRepairNo__c,PartsreadyDate__c from Repair__c where Id = :rpr.Id];
 
        NFM117Rest.GeDatas GeDatas = new NFM117Rest.GeDatas();
        NFM117Rest.GeData GeData = new NFM117Rest.GeData();
        GeDatas.GeData = new NFM117Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        GeData.SAPRepairNo = 'NFM117Repair1';
        GeData.PartsreadyDate = '2022-06-06T00:00:00';
 
 
        //System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM117', GeDatas.GeData);
        NFM117Rest.executefuture(rowData.Id);
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM117', GeDatas.GeData);
        NFM117Rest.executefuture(rowData.Id);
 
        //System.assertEquals('2022-06-06', rpr2.PartsreadyDate__c);
        //System.Test.stopTest();
    }
    static testMethod void testMethod2() {
        //Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM117","MessageGroupNumber":"20210000005088"},"GeData":[{"SAPRepairNo":"000010267138","PartsreadyDate":"2022-06-06T00:00:00"}]}';
        req.requestURI = 'services/apexrest/NFM117/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM117Rest.execute();
 
        //Test.stopTest();
    }
    static testMethod void testMethod3() {
        //Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM117","MessageGroupNumber":"20210000005088"},"GeData":[{"SAPRepairNo":"","PartsreadyDate":"2022-06-06T00:00:00"}]}';
        req.requestURI = 'services/apexrest/NFM117/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM117Rest.execute();
 
        //Test.stopTest();
    }
    static testMethod void testMethod4() {
        //Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SAP","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM117","MessageGroupNumber":"20210000005088"},"GeData":[{"SAPRepairNo":"000010267138","PartsreadyDate":""}]}';
        req.requestURI = 'services/apexrest/NFM117/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM117Rest.execute();
 
        //Test.stopTest();
    }
}