@IsTest
public with sharing class NFM501ControllerTest {

	@testSetup
	static void makeTestQLM() {
		// List<BatchIF_Transfer__c> QLMoldMarkTransfers = new List<BatchIF_Transfer__c>();
		BatchIF_Transfer__c transfer1 = new BatchIF_Transfer__c();
		transfer1.Table__c          = 'QLMoldMark';
		// transfer1.Column__c         = '*';
		// transfer1.External_Value__c = 'PCS';
		transfer1.Internal_Value__c = '*';
		// QLMoldMarkTransfers.add(transfer1);
		insert transfer1;

		List<BatchIF_Transfer__c> NFM501GainEndTimeTransfers = new List<BatchIF_Transfer__c>();
		BatchIF_Transfer__c transfer2 = new BatchIF_Transfer__c();
		transfer2.Table__c          = 'NFM501GainEndTime';
		transfer2.NFM501_Gain_End_Time__c = Datetime.now();
		// transfer1.Column__c         = '*';
		// transfer1.External_Value__c = 'PCS';
		// transfer1.Internal_Value__c = '*';
		NFM501GainEndTimeTransfers.add(transfer2);
		insert NFM501GainEndTimeTransfers;

		List<BatchIF_Transfer__c> NFM501TokenTransfers = new List<BatchIF_Transfer__c>();
		BatchIF_Transfer__c transfer3 = new BatchIF_Transfer__c();
		transfer3.Table__c          = 'NFM501Token';
		transfer3.NFM501_Token__c = null;//'eyJhbGciOiJIUzUxMiJ9.eyJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImV4cCI6MTYyNDI2MTc1OX0.s55zh9SSpwqRdp1wXH43_wEGpwlZtMfRgl1x8t69A-N0H7QrzRNmK5MNqNGGLhQ2LL_AbMSJmDfwO5chgwndoA';
		// transfer1.Column__c         = '*';
		// transfer1.External_Value__c = 'PCS';
		// transfer1.Internal_Value__c = '*';
		NFM501TokenTransfers.add(transfer3);
		insert NFM501TokenTransfers;

		BatchIF_Log__c rowData = new BatchIF_Log__c();
		rowData.Type__c = 'NFM501';
		rowData.RowDataFlg__c = true;
		rowData.MessageGroupNumber__c = transfer1.Internal_Value__c;
		insert rowData;

		BatchIF_Log__c iflog = new BatchIF_Log__c();
		iflog.Type__c = 'NFM501';
		iflog.RowDataFlg__c = false;
		iflog.Log__c = ' ';
		iflog.ErrorLog__c = ' ';
		iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
		insert iflog;

	}

	@IsTest
	static void myTest() {
		BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c,
		                          Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c,
		                          Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,
		                          NFM501Future_Count__c,
		                          NFM501_Web_Annex_Count__c from BatchIF_Log__c
		                          where RowDataFlg__c = true];
		BatchIF_Log__c iflog = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c,
		                        Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c,
		                        Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,
		                        NFM501Future_Count__c,
		                        NFM501_Web_Annex_Count__c from BatchIF_Log__c Limit 1];

		Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
		Test.startTest();
		NFM501Controller.sendRequest(rowData.Id, iflog.Id, false);
		// Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMockEx());
		NFM501Controller.againSendRequest(iflog, 'retry_cnt__c', rowData);
		NFM501Controller.againSendExceptionRequest(iflog, 'retry_cnt__c', rowData,
		        '502抛出异常：' + '错误次数已经超过自动收信设定的最大次数，请手动收信');
		NFM501Controller.NFM501againSendExceptionRequest(iflog, 'retry_cnt__c', rowData, '501抛出异常：' +
		        '错误次数已经超过自动收信设定的最大次数，请手动收信');
		// NFM501Controller.TwoMarkEqualAgainSend();
		// NFM501Controller.NFM501againSendExceptionRequest(iflog, 3, rowData);
		Test.stopTest();
	}

	@IsTest
	static void myTest1() {
		BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c,
		                          Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c,
		                          Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,
		                          NFM501Future_Count__c,
		                          NFM501_Web_Annex_Count__c from BatchIF_Log__c
		                          where RowDataFlg__c = true];
		BatchIF_Log__c iflog = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c,
		                        Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c,
		                        Log11__c, Log12__c, MessageGroupNumber__c, retry_cnt__c,
		                        NFM501Future_Count__c,
		                        NFM501_Web_Annex_Count__c from BatchIF_Log__c Limit 1];
		Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMockEx());
		Test.startTest();
		NFM501Controller.sendRequest(rowData.Id, iflog.Id, false);
		NFM501Schedule2.test();
		NFM501Controller.test();
		Test.stopTest();
	}

}