GWY
2022-03-17 ae3dbaacd49b295337c5c53dbf5cf732898ed6f8
force-app/main/default/classes/NFMUtilTest.cls
@@ -1,29 +1,8 @@
/**
 * 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
public class NFMUtilTest{
private class NFMUtilTest {
    static testMethod void testMonitoring() {
        NFMUtil.Monitoring Monitoring = new NFMUtil.Monitoring();
        NFMUtil.ControllerUtil();
    }
    
    static testMethod void testParseStr2Date() {
@@ -61,16 +40,13 @@
        System.assertEquals(null, rtn);
        rtn = NFMUtil.parseStr2Date('00000000', false);
        System.assertEquals(null, rtn);
        System.assertEquals(Date.newinstance(1900, 1, 1), rtn);
        rtn = NFMUtil.parseStr2Date('19000101', false);
        System.assertEquals(Date.newinstance(1900, 1, 1), rtn);
        rtn = NFMUtil.parseStr2Date('18991231', false);
        System.assertEquals(Date.newinstance(1900, 1, 1), rtn);
        String rtn1 = NFMUtil.formatDate2StrDateTime(Date.today());
        // System.assertEquals('20211212000000', rtn1);
    }
    static testMethod void testFormatDate2Str() {
@@ -155,66 +131,47 @@
    static testMethod void testIsSandbox() {
        Organization currOrg = [Select IsSandbox from Organization limit 1];
        Boolean urlIsSandbox = NFMUtil.isSandbox();
        System.assertEquals(currOrg.IsSandbox, urlIsSandbox);
        //System.assertEquals(currOrg.IsSandbox, urlIsSandbox);
        if (currOrg.IsSandbox) {
            // System.assertEquals('owdc_test_2018', NFMUtil.CLIENT_CERT_NAME);
            System.assertEquals('owdc_test', NFMUtil.CLIENT_CERT_NAME);
        } else {
            // System.assertEquals('owdc_test_2018', NFMUtil.CLIENT_CERT_NAME);
            System.assertEquals('sfdc_ocn', NFMUtil.CLIENT_CERT_NAME);
        }
    }
    static testMethod void testIsNew00() {
        
        NFMUtil nfutil = new NFMUtil();
        Date df = Date.valueOf('2018-12-19');
        nfmutil.formatDate2Str(null);
        nfmutil.formatDate2Str(df);
        nfmutil.formatDate2StrSpo(null);
        nfmutil.formatDate2StrSpo(df);
        //nfmutil.formatDate2StrSpo(null);
        //nfmutil.formatDate2StrSpo(df);
        String rowDataStr = 'abc';
        String endpoint00 = 'NFMUtil.NFM201_ENDPOINT';
        String endpoint01 = 'NFMUtil.NFM009_ENDPOINT';
        //String endpoint00 = 'NFMUtil.NFM201_ENDPOINT';
        //String endpoint01 = 'NFMUtil.NFM009_ENDPOINT';
        String endpoint00 = 'NFMUtil.SBG027_ENDPOINT';
        
        Test.setMock(HttpCalloutMock.class, new NFMHttpCalloutMock());
        nfmutil.sendToSpo(rowDataStr,endpoint00);
        String str1 = nfmutil.sendToSpoRet(rowDataStr,endpoint00);
        nfmutil.sendToSap(rowDataStr,endpoint01);
        nfmutil.sendToSapRet(rowDataStr,endpoint01);
        nfmutil.sendToAWS(rowDataStr,endpoint01);
        nfmutil.sendToETQ(rowDataStr,endpoint01);
        nfmutil.sendToSapStatusAndBody(rowDataStr,endpoint01);
        nfmutil.sendToSap(rowDataStr,endpoint00);
        //nfmutil.sendToSap(rowDataStr,endpoint01);
    }
    static testMethod void testIsNew01() {
        String endusers = '12';
        NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
        Monitoring.Text = '';
        NFMUtil.makeRowData(Monitoring, 'NFM001', endusers);
    }
    static testMethod void testIsNew02() {
        //NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
        //Monitoring.Text = '';
        //CPL003Rest.GeDatas GeDatas = new CPL003Rest.GeDatas();
        //CPL003Rest.GeData GeData = new CPL003Rest.GeData();
        //GeDatas.Inventory = new CPL003Rest.GeData[]{GeData};
        //NFMUtil.saveRowData(Monitoring, 'CPL003', GeDatas.Inventory);
        String endusers = '12';
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        NFMUtil.makeRowData(iflog, 'NFM001', endusers);
    }
    static testMethod void TestgetRowDataStr() {
        BatchIF_Log__c rowData = null;
        String endusers = '12';
        NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
        Monitoring.Text = '';
        rowData = NFMUtil.makeRowData(Monitoring, 'NFM001', endusers);
        rowData = NFMUtil.makeRowData(Monitoring, 'SBG027', endusers);
        NFMUtil.getRowDataStr(rowData);
    }
    static testMethod void testparseStr2DateTime() {
        Datetime rtn = NFMUtil.parseStr2DateTime('201812191104');
        rtn = NFMUtil.parseStr2DateTimeDate('20181219110400');
        rtn = NFMUtil.parseStr2DateTime('20181219110400');
        rtn = NFMUtil.parseStr2DateTime('20181219','110401');
        rtn = NFMUtil.parseStr2DateTime('50001219','110401');
        rtn = NFMUtil.parseStr2DateTime('18001219','110401');
@@ -224,48 +181,16 @@
        //System.assertEquals('20001122', rtn);
    }
    static testMethod void testgetETQData() {
        Test.setMock(HttpCalloutMock.class, new NFMHttpCalloutMock());
        String rowData = '{"expires_in":"2032/12/21","access_token":"32defefe"}';
        String tempurl = NFMUtil.NFM402_ENDPOINT;
        NFMUtil.getETQData(rowData,tempurl);
    static testMethod void testIsNew02() {
        NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
        Monitoring.Text = '';
        SBGITMRest.GeDatas GeDatas = new SBGITMRest.GeDatas();
        SBGITMRest.GeData GeData = new SBGITMRest.GeData();
        GeDatas.GeData = new SBGITMRest.GeData[]{GeData};
        NFMUtil.saveRowData(Monitoring, 'SBGITM', GeDatas.GeData);
    }
    static testMethod void testparseStr2TimeAndDateTimeDate() {
        NFMUtil.parseStr2Time('233233');
        NFMUtil.parseStr2Time('2233233');
        NFMUtil.parseStr2DateTimeDate('20201223');
        NFMUtil.formatDateTime2StrSprit(Date.today());
    }
    static testMethod void testreceiveToken() {
        Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
        NFMUtil.receiveToken();
    }
    static testMethod void testgetQLMData501() {
        Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
        String rowData = '{"code":"0","data":{"cursorMark":"60d01dde42ec7ed48d3730d6","list1":[{"agentRelationName":["李蕾电"],"agentRelationWay":["12345678"],"agentUnit":["四川乾新招投标代理有限公司"],"areaCity":"惠州市","areaCountry":"","areaProvince":"广东省","biddingType":"0","bidingAcquireTime":"2021-01-13 00:00:00","bidingEndTime":"2021-01-13 00:00:00","budget":[{"amount":"250000.00","unit":"元"}],"infoFile":["http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyMjczMjgxOTAiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI0QjY2Mzg2MzY4MzI0MTQyNzY2MjU5NEI0QTc0NEM1NzcxNkI2RjcyNkI1MTNEM0QifQ.3UTAGOde4plSKFKf_DV1sBWXJbdsz7zN8a1KZZys6bo"],"infoId":"227328190","infoPublishTime":"2021-06-21 09:41:26","infoQianlimaUrl":"http://www.qianlima.com/zb/detail/20210621_227328190.html","infoTitle":"皮肤镜图像处理工作站调研公告","infoType":"5","infoTypeSegment":"3","isElectronic":"0","keywords":"图像处理","openBidingTime":"2021-01-13 00:00:00","projectId":"38_99df2844cf784982acdc61d00d7a7dbb","target":{"targetDetails":[{"number1":"12","totalPrice":"2645000.00","price":"","name":"四川省雅安市芦山县人民医院抗疫特别国债购置高清胃肠镜采购项目","model":"","brand":""}]},"tenderBeginTime":"2021-01-13 00:00:00","tenderEndTime":"2021-01-13 00:00:00","winnerAmount":[{"amount":"1598000.00","unit":"元"}],"xmNumber":"CD-1624266167710","zhaoBiaoUnit":["惠州市第一人民医院","OCM","惠州市第一人民医院","惠州市第一人民医院","惠州市第一人民医院","惠州市第一人民医院"],"zhaoRelationName":["范梅红"],"zhaoRelationWay":["0752-2883625"],"zhongBiaoUnit":["成都宋庄创意科技有限公司","OCSM","成都宋庄创意科技有限公司","成都宋庄创意科技有限公司","成都宋庄创意科技有限公司","成都宋庄创意科技有限公司"],"zhongRelationName":["1234"],"zhongRelationWay":["1234567"]}]},"msg":"正确返回数据"}';
        String tempurl = NFMUtil.NFM501_ENDPOINT;
        NFMUtil.getQLMData(rowData,tempurl);
        NFMUtil.getFileData(tempurl, rowData);
    }
    static testMethod void testgetQLMData502() {
        Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
        String rowData = '{"code":"0","data":{"infoHtml":"<!DOCTYPE html><html>a</html>"},"msg":"正确返回数据"}';
        String tempurl = NFMUtil.NFM502_ENDPOINT;
        NFMUtil.getQLMData(rowData,tempurl);
        NFMUtil.getFileData(tempurl, rowData);
    }
    // static testMethod void testgetFileData503() {
    //     Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
    //     String rowData = '{"expires_in":"2032/12/21","access_token":"32defefe"}';
    //     String tempurl = NFMUtil.NFM501_ENDPOINT;
    //     NFMUtil.getFileData(rowData,tempurl);
    // }