@isTest
public with sharing class NFM503InfoFileBatchTest {
	@testSetup
	static void makeTestQLM503() {
		// ADD BY SUSHANHU FOR PI START
		TestDataUtility.CreatePIPolicyConfiguration('NFM503');
		// ADD BY SUSHANHU FOR PI END
		BatchIF_Transfer__c transfer1 = new BatchIF_Transfer__c();
		transfer1.Table__c          = 'QLMoldMark';
		transfer1.Internal_Value__c = '*';
		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();
		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 = 'eyJhbGciOiJIUzUxMiJ9.eyJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImV4cCI6MTYyNDI2MTc1OX0.s55zh9SSpwqRdp1wXH43_wEGpwlZtMfRgl1x8t69A-N0H7QrzRNmK5MNqNGGLhQ2LL_AbMSJmDfwO5chgwndoA';
		NFM501TokenTransfers.add(transfer3);
		insert NFM501TokenTransfers;

		Tender_information__c Ten = new Tender_information__c();
		Ten.Name = '123456';
		Ten.InfoTitle__c = '123456';
		Ten.InfoType__c = '1：预告';
		Ten.ProjectId__c = '38_99df2844cf784982acdc61d00d7a7dbb';
		insert Ten;

		bidInfoFile__c bidInfoFile  = new bidInfoFile__c();
		bidInfoFile.Tender_information__c = Ten.Id;
		bidInfoFile.infoAddress__c = 'http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyNjU0MjU3NzkiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI2NzcxNEE3NjM0NkY3OTQzNTczMjVBMzg1NjY3NkY0NzdBNTE2NDVBNjM3NzNEM0QifQ.lR9LNgndLPmi3hxlaWru6xeKsPXTYnNaFxGVzmzoqM8';
		insert bidInfoFile;
	}

	@IsTest
	static void Test503() {
		List<bidInfoFile__c> bidInfoFileList = [Select Id, infoAddress__c, ErrorMessage__c,
		                                        Tender_information__c, Tender_information__r.Id, 
												Tender_information__r.InfoType__c, 
		                                        isProcessed__c from bidInfoFile__c];
		Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
		Test.StartTest();
		// Database.executeBatch( new NFM503InfoFileBatch(bidInfoFileList[0].id, false), 1);
		NFM503InfoFileBatch bt = new NFM503InfoFileBatch(bidInfoFileList[0].id, false);
		bt.start(null);
		// Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
		bt.execute(null,bidInfoFileList);
		// Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMock());
		bt.finish(null);
		NFM503InfoFileSchedule.assignOneMinute();
		NFM503InfoFileSchedule.test();
		Test.stopTest();

	}
	@IsTest
	static void myTest1() {
		List<bidInfoFile__c> bidInfoFileList = [Select Id, infoAddress__c, ErrorMessage__c,
		                                        Tender_information__c, Tender_information__r.Id,  
												Tender_information__r.InfoType__c, 
		                                        isProcessed__c from bidInfoFile__c];
		Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMockEx());
		Test.StartTest();
		Database.executeBatch( new NFM503InfoFileBatch(bidInfoFileList[0].id), 1);
		Test.stopTest();
	}
	// @IsTest
	// static void myTest2() {
	// 	List<bidInfoFile__c> bidInfoFileList = [Select Id, infoAddress__c, ErrorMessage__c,
	// 	                                        Tender_information__c, Tender_information__r.Id, 
	// 	                                        isProcessed__c from bidInfoFile__c];
	// 	Test.setMock(HttpCalloutMock.class, new NFM501HttpCallMockEx());
	// 	Test.StartTest();
	// 	Database.executeBatch( new NFM503InfoFileBatch(bidInfoFileList[0].id, false, false), 1);
	// 	Test.stopTest();
	// }
	public HTTPResponse Qianlimarespond(HTTPRequest req){
		HttpResponse res =new HttpResponse();
		res.setHeader('Content-Type', 'application/json');
		String body ='{"data":{"list1":[{"DataId":"958844903104712705","agentRelationWayEncrypted":["084f251281c90c15222080ced4cc9f13"],"agentRelationNameEncrypted":["6d601562f339a79737ca55ff89d1d660"],"zhongRelationWayEncrypted":[],"zhongRelationNameEncrypted":[],"zhaoRelationWayEncrypted":["43267085b22691c3886bd9374ef6a7a6"],"zhaoRelationNameEncrypted":["905ebdc831f844cd89de79f7efb542c9"],"allKeywords":"国产,进口","moreZhongBiaoUnit":[],"zhongRelationWay":[],"zhongRelationName":[],"zhongBiaoUnit":["重庆友一家医疗技术有限公司"],"zhaoRelationWay":["***********"],"zhaoRelationName":["***"],"zhaoBiaoUnit":["龙里县中医医院"],"xmNumber":"GZLDN-2022-ZCF002","winnerAmount":[{"unit":"元","amount":"2186600.00"}],"tenderEndTime":"","tenderBeginTime":"","target":null,"projectId":"4432657061de4983bd8da8ed6edcb3d8","openBidingTime":"","keywords":"电切镜,光学视管,电子肠镜,纤维镜,胃镜,超声刀,宫腔镜,内窥镜,窥镜,腔镜,内镜,宫腔电切,肠镜,电子胃镜,宫腔电切镜","isElectronic":"0","infoTypeSegment":"11","infoType":"3","infoTitle":"龙里县中医医院医用设备采购项目中标（成交）公告","infoQianlimaUrl":"http://www.qianlima.com/zb/detail/20220329_265218006.html","infoPublishTime":"2022-03-29 16:15:42","infoId":"265218006","infoFile":["http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyNjUyMTgwMDYiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI3MzUxNjYzMTRENkY3OTZFNTU3NTcxNDE1MzZCMzcyRjY4MzUzMjcwMzU1MTNEM0QifQ.v1ADEHTb0JJcuV1pviecF0UXeYwh_q50a0anLPXyw0M","http://cusdata.qianlima.com/vip/info/download/V2/eyJhbGciOiJIUzI1NiJ9.eyJpbmZvSWQiOiIyNjUyMTgwMDYiLCJhcHBLZXkiOiIwNzBmMDBiZi02NGYxLTQ3MjAtYThkOC1iYmUxYWE5NzZkMjIiLCJhcHBTZWNyZXQiOiI2N0JCMkJBRkM4QUEwQkEwQ0FCQjM3Q0JGNTBFQzI5MiIsImZpbGVVcmwiOiI1MTVBNjc0QzcxNkEzMzQ0NzY2MTczNzEzMDZGN0E0OTYyNTUzMDY4Njc2NzNEM0QifQ.cTnxp9zsjKxNYge8xFyJdYrvlWner6riuzWfo1pEOnw"],"budget":[{"unit":"元","amount":"2250000.00"}],"bidingEndTime":"","bidingAcquireTime":"","biddingType":"0","areaProvince":"贵州省","areaCountry":"龙里县","areaCity":"黔南布依族苗族自治州","agentUnit":["贵州联德诺招标咨询有限公司"],"agentRelationWay":["***********"],"agentRelationName":["***"]}],"cursorMark":"6242f5a6203862d0acf43397"},"code":"0","msg":"正确返回数据"}';
		res.setBody(body);
		res.setStatusCode(200);
		res.setStatus('OK');
		return res;
	}
}