buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
@isTest
public class AWSServiceTool2Test {
    
    @TestSetup
    static void setup(){
        TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Contact'});
    } 
    
    @isTest
    static void Test1(){
        
        List<Contact> lra = new List<Contact>();
        lra.add(new Contact(
            LastName='123'
        ));
        insert lra;
        
        Test.setMock(HttpCalloutMock.class, new HttpMock(lra[0].Id));
 
        
        Test.startTest();
        //system.debug(PIHelper.getPIIntegrationInfo('Contact').newEncryptUrl);
        AWSServiceTool2.EncryptPushCore(Json.serialize(lra),'Contact');
        AWSServiceTool2.EncryptPushFuture(null,null);
        Test.stopTest();
    }
 
    @isTest
    static void Test2(){
        List<Contact> lra = new List<Contact>();
        lra.add(new Contact(
            LastName='123',
            Aws_Data_Id__c = '123456'
        ));
        insert lra;
        Test.setMock(HttpCalloutMock.class, new HttpMock(lra[0].Id));
 
        
        Test.startTest();
        //system.debug(PIHelper.getPIIntegrationInfo('Contact').newEncryptUrl);
        AWSServiceTool2.EncryptPushCore(Json.serialize(lra),'Contact');
        Test.stopTest();
    }
 
    @isTest
    static void Test3(){
        Test.setMock(HttpCalloutMock.class, new HttpMock());
 
 
        Test.startTest();
        AWSServiceTool2.EncryptPushData(new string[]{'0031000000O4Cff'});
 
        Test.stopTest();
    }
 
 
    /*
    @isTest
    static void Test3(){
        Test.setMock(HttpCalloutMock.class, new HttpMock());
        Rental_Apply__c ra =  new Rental_Apply__c();
        insert ra;
        //PIHelper.getPIIntegrationInfo('Rental_Apply__c');
        List<Rental_Apply__c> lra = new List<Rental_Apply__c>();
        lra.add(new Rental_Apply__c(
            Old_Rental_Apply__c = ra.Id
        ));
        //insert lra;
        Test.startTest();
        AWSServiceTool2.decryptInsertCore(Json.serialize(lra),'Rental_Apply__c');
        Test.stopTest();
    }*/
    
    
    
    class HttpMock implements HttpCalloutMock{
        
        string rid  = '';
        public HttpMock(){
        }
        public HttpMock(string rid){
            this.rid = rid;
        }
        public HTTPResponse respond(HTTPRequest request) {
        // 创建一个假的回应
        System.debug('------------------------------------------------------');
        HttpResponse response = new HttpResponse();
        string body = '';
        system.debug(request.getEndpoint());
        string url = request.getEndpoint();
            
        if(url.contains('token')){
            system.debug('url=token');
            response.setHeader('Content-Type', 'application/json');
            body='{ "message": "", "object": "freqfewqfewewfewfew", "status": "", "success": true, "timestamp": 0, "txId": "" }';            
        } else if(url.toLowerCase().contains('insert')){
            system.debug('url=Insert');
            response.setHeader('Content-Type', 'application/json');
            body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "'+rid+'" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';            
        } else if(url.toLowerCase().contains('update')){
            system.debug('url=update');
            response.setHeader('Content-Type', 'application/json');
            body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "'+rid+'" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }';            
        } else{
            
        }
        
        response.setBody(body);
        response.setStatus('OK');
        response.setStatusCode(200);
        return response;
        // }
    }
    }
}