@isTest
private class NFMUtilTest {

    static testMethod void testMonitoring() {
        NFMUtil.Monitoring Monitoring = new NFMUtil.Monitoring();
    }
    
    static testMethod void testParseStr2Date() {
        Date rtn = NFMUtil.parseStr2Date(null);
        System.assertEquals(null, rtn);
        
        rtn = NFMUtil.parseStr2Date('2000');
        System.assertEquals(null, rtn);
        
        rtn = NFMUtil.parseStr2Date('2000123123');
        System.assertEquals(null, rtn);

        rtn = NFMUtil.parseStr2Date('2000AB13');
        System.assertEquals(null, rtn);

        rtn = NFMUtil.parseStr2Date('20001231');
        System.assertEquals(Date.newinstance(2000, 12, 31), rtn);

        rtn = NFMUtil.parseStr2Date('99991231');
        System.assertEquals(Date.newinstance(4000, 12, 31), rtn);

        rtn = NFMUtil.parseStr2Date('40001231');
        System.assertEquals(Date.newinstance(4000, 12, 31), rtn);

        rtn = NFMUtil.parseStr2Date('40010101');
        System.assertEquals(Date.newinstance(4000, 12, 31), rtn);

        rtn = NFMUtil.parseStr2Date('00000000');
        System.assertEquals(null, rtn);

        rtn = NFMUtil.parseStr2Date('19000101');
        System.assertEquals(null, rtn);

        rtn = NFMUtil.parseStr2Date('18991231');
        System.assertEquals(null, rtn);

        rtn = NFMUtil.parseStr2Date('00000000', false);
        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);
    }

    static testMethod void testFormatDate2Str() {
        String rtn = NFMUtil.formatDate2Str(null);
        System.assertEquals(null, rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(2000, 11, 22));
        System.assertEquals('20001122', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(1900, 01, 02));
        System.assertEquals('19000102', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(1900, 01, 01));
        System.assertEquals('19000101', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(1899, 12, 31));
        System.assertEquals('19000101', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(4000, 12, 30));
        System.assertEquals('40001230', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(4000, 12, 31));
        System.assertEquals('99991231', rtn);

        rtn = NFMUtil.formatDate2Str(Date.newinstance(4001, 1, 1));
        System.assertEquals('99991231', rtn);
    }
    
    static testMethod void testGetMapValue() {
        BatchIF_Log__c iflog = new BatchIF_Log__c();

        Map<String, String> transferMap = new Map<String, String>();
        transferMap.put('ckey1', 'value1');

        String rtn = NFMUtil.getMapValue(null, null, null, iflog);
        System.assertEquals(null, rtn);
        
        rtn = NFMUtil.getMapValue(null, null, 'key', iflog);
        System.assertEquals('key', rtn);

        rtn = NFMUtil.getMapValue(transferMap, 'c', null, iflog);
        System.assertEquals(null, rtn);
        System.assertEquals(null, iflog.ErrorLog__c);

        rtn = NFMUtil.getMapValue(transferMap, 'c', 'key', iflog);
        System.assertEquals('key', rtn);
        System.assertEquals(true, iflog.ErrorLog__c.indexOf('Please') >= 0);

        rtn = NFMUtil.getMapValue(transferMap, 'c', 'key1', iflog);
        System.assertEquals('value1', rtn);

        rtn = NFMUtil.getMapValue(transferMap, '', 'ckey1', iflog);
        System.assertEquals('value1', rtn);

        rtn = NFMUtil.getMapValue(transferMap, null, 'ckey1', iflog);
        System.assertEquals('value1', rtn);
    }

    static testMethod void testTrimLeft() {
        String rtn = NFMUtil.trimLeft('AAAA70000', 'A');
        System.assertEquals('70000', rtn);

        rtn = NFMUtil.trimLeft('000070000', '0');
        System.assertEquals('70000', rtn);

        rtn = NFMUtil.trimLeft(' 000070000', '0');
        System.assertEquals(' 000070000', rtn);

        rtn = NFMUtil.trimLeft('0 00070000', '0');
        System.assertEquals(' 00070000', rtn);

        rtn = NFMUtil.trimLeft('', '0');
        System.assertEquals('', rtn);

        rtn = NFMUtil.trimLeft('0 00070000', null);
        System.assertEquals(null, rtn);

        rtn = NFMUtil.trimLeft(null, '0');
        System.assertEquals(null, rtn);
    }

    static testMethod void testIsSandbox() {
        Organization currOrg = [Select IsSandbox from Organization limit 1];
        Boolean urlIsSandbox = NFMUtil.isSandbox();
        //System.assertEquals(currOrg.IsSandbox, urlIsSandbox);
        if (currOrg.IsSandbox) {
            System.assertEquals('owdc_test', NFMUtil.CLIENT_CERT_NAME);
        } else {
            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);
        String rowDataStr = 'abc';
        //String endpoint00 = 'NFMUtil.NFM201_ENDPOINT';
        //String endpoint01 = 'NFMUtil.NFM009_ENDPOINT';
        
        String endpoint00 = 'NFMUtil.SBG027_ENDPOINT';
        
        Test.setMock(HttpCalloutMock.class, new NFMHttpCalloutMock());
        nfmutil.sendToSap(rowDataStr,endpoint00);
        //nfmutil.sendToSap(rowDataStr,endpoint01);

    }

    static testMethod void TestgetRowDataStr() {
        BatchIF_Log__c rowData = null;
        String endusers = '12';
        NFMUtil.Monitoring Monitoring   = new NFMUtil.Monitoring();
        Monitoring.Text = '';
        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');
        //System.assertEquals(null, rtn);

        //rtn = NFMUtil.parseStr2DateTime(Date.newinstance(2000, 11, 22));
        //System.assertEquals('20001122', rtn);
    }

    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);
       
    }




}