游畅
2023-04-29 cc266a1e4080bb3ecc47ea4a202dd549545111e1
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
@isTest
public with sharing class NFM209RestTest {
     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          = 'Account';
        transfer.Column__c         = 'TradeComplianceStatus__c';
        transfer.External_Value__c = 'W';
        transfer.Internal_Value__c = '白名单';
        transfers.add(transfer);
        transfer = new BatchIF_Transfer__c();
        transfer.Table__c          = 'Account';
        transfer.Column__c         = 'TradeComplianceStatus__c';
        transfer.External_Value__c = 'B';
        transfer.Internal_Value__c = '黑名单';
        transfers.add(transfer);
        insert transfers;
        
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.Name         = 'NFM209TestCompany';
        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  = 'NFM209TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        company = [select Id, Name,Management_Code_Auto__c from Account
                                where Id = :company.Id];
        NFM209Rest.GeDatas GeDatas = new NFM209Rest.GeDatas();
        NFM209Rest.GeData GeData = new NFM209Rest.GeData();
        GeDatas.GeData = new NFM209Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
 
        GeData.custCode = company.Management_Code_Auto__c;                 
        GeData.complStatus = 'B';                 
        GeData.orgSysId='123';                   
        GeData.glbBusiNo='123';                  
        GeData.custTp='123';                      
        GeData.entityTp='123';                  
        GeData.custName='123';                    
        //System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM209', GeDatas.GeData);
        NFM209Rest.executefuture(rowData.Id);
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM209', GeDatas.GeData);
        NFM209Rest.executefuture(rowData.Id);
}
 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":[{"custCode":"8098008","complStatus":"黑名单","orgSysId":"00987","glbBusiNo":"001","custTp":"Person","entityTp":"经销商","custName":"大连东控睿康医疗管理有限公司"}]}';
        req.requestURI = 'services/apexrest/NFM209/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM209Rest.execute();
 
        //Test.stopTest();
    }
}