高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class NFM704RestTest {
    @testSetup
   static void test_method_one(){
 
        List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List < RecordType > rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '戦略科室分類 消化科'
        ];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List < RecordType > rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '診療科 消化科'
        ];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Is_Active__c = '有効';
        company.Name = 'NFM105TestCompany';
        company.AwaitToSendAWS__c = true;
        upsert company;
 
        Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId =: company.Id and RecordTypeId =: rectSct[0].Id];
 
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name = '*';
        depart.Department_Name__c = 'NFM105TestDepart';
        depart.ParentId = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c = company.Id;
        depart.AgentCode_Ext__c = 'Test202201';
        upsert depart;
    
    }
 
    @isTest static void test_method_two(){
 
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112311320","Text":"","Tag":"","Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM704","MessageGroupNumber":""},"GeData":[{"StaffMCode": "C000019313","HospitalMCode": "010","OfficeMCode": "Test202201", "HcpNo": "111", "HCPLevel": "2", "Name": "刘刚", "Mobile": "13809233181"}]}';
        req.requestURI = 'services/apexrest/NFM704/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueOf(JsonMsg);
 
        RestContext.request = req;
        RestContext.response = res;
        
        NFM704Rest.doPost();
    }
}