@isTest
private class NFM703WebServiceTest {
    
    private static User getUser() {
        String flag='NG2';
        String d1='产品试用';
        String dept='医疗华北营业本部';
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Province__c = '北京';
        user.Dept__c = dept;
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        // insert user;
         System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user;
        }
        return user;
    }
    @isTest
    static void testCallOut1() {
        OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        mp1.Name = '其他';
        mp1.Province__c = '北京市';
        mp1.Window1__c = getUser().Id;
        insert mp1;

        StaticParameter.EscapeCampain =false;
        StaticParameter.shareToOSCMFlag = false; 
        Campaign cam = new Campaign();
        cam.Name = 'test011111 (2021/12/15 - 2021/12/20)';
        cam.StartDate = Date.today().addDays(15);
        cam.EndDate = Date.today().addDays(18);
        cam.Name2__c = '1234';
        cam.Status = '申请中';
        cam.Mailflg_after45__c = true;
        cam.Mailflg_cancel__c = true;
        cam.Mailflg_before15__c = true;
        cam.Mailflg_before7__c = true;
        cam.Mailflg_after3__c = true;
        cam.HostName__c = '1';
        cam.IF_Approved__c = true;
        cam.cooperatorCompany__c = '2222';
        cam.RecordTypeId = System.label.RecordType_CampaignService;
        // cam.OwnerId = getUser().Id;
        cam.Num__c = 'MT-GI-202112-5772';
// StartDate
// EndDate
		cam.Budget_Type__c = '新产品上市';
		cam.OfficeCategory__c = null;
		cam.Meeting_Type__c = '主办会';
		cam.Activity_Type_Name__c = null;
		cam.State_Master__r = null;
		cam.City_Master__r = null;
		cam.WorkshopPlace__c = '北京';
		cam.Expected_Olympus_Attendance__c = null;
		cam.Expected_Hcp_Attendance__c = null;
        insert cam;
		
        List < Campaign > camList = [select Id,IF_Approved__c from Campaign];
        // System.assertEquals(camList.size(),1);
        System.assertEquals(camList[0].IF_Approved__c,true);

        Test.startTest();

        List < Id > idList = new List < Id > ();
        for (Campaign cam1: camList) {
            idList.add(cam1.Id);
        }

        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = '{"Monitoring":{"TransmissionDateTime":"20220209150125","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"OBPM","NumberOfRecord":"1","MessageType":"NFM703","MessageGroupNumber":"20220209150125"},"GeData":[{"WorkshopPlace":"北京","StateMaster":null,"StartDate":"2021-12-15","OfficeCategory":null,"Num":"MT-GI-202112-5772","Name":"test011111 (2021/12/15 - 2021/12/20)","MeetingType":"主办会","HostName":"1","ExpectedOlympusAttendance":null,"ExpectedHcpAttendance":null,"EndDate":"2021-12-20","CooperatorCompany":"2222","CityMaster":null,"BudgetType":"新产品上市","ActivityTypeName":null}]}';
        iflog.Type__c = 'NFM703';
        // insert iflog;
        // BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c += 'test start \n';
        insert iflog;
        
        // System.assertEquals(iflog.retry_cnt__c,0);
        NFM703WebService.sendToOBPM(iflog.Id, idList);
        Test.stopTest();
    }
}