@isTest
private class NFM707RestTest {

    @testSetup
    static void makeTestRepair() {
    	Application_for_Conference_Adjudication__c afca = new Application_for_Conference_Adjudication__c();
    	afca.MeetingApprovedNo__c = '202112161007';
    	afca.Num__c = '1234';
    	insert afca;
    }
    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 test_1(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        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 = 'test campaign';
        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.cooperatorCompany__c = '1';
        cam.Num__c = '6666';
        cam.MeetingApprovedNo__c = '202112161003';
        cam.RecordTypeId = System.label.RecordType_CampaignService;
        // cam.OwnerId = getUser().Id;
        insert cam;
		
        // String JsonMsg = '[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi0","Num":"","MeetingApprovedNo":"202112161007","Competitor":"ceshi3"}]';
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112151103","Text":null,"Tag":null,"Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM707","MessageGroupNumber":null},"GeData":[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi4","Num":"6666","MeetingApprovedNo":"202112161007","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_2(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        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 = 'test campaign';
        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.cooperatorCompany__c = '1';
        cam.Num__c = '6666';
        cam.MeetingApprovedNo__c = '202112161007';
        cam.RecordTypeId = System.label.RecordType_CampaignService;
        // cam.OwnerId = getUser().Id;
        insert cam;
		
        // String JsonMsg = '[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi0","Num":"","MeetingApprovedNo":"202112161007","Competitor":"ceshi3"}]';
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112151103","Text":null,"Tag":null,"Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM707","MessageGroupNumber":null},"GeData":[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi4","Num":"","MeetingApprovedNo":"","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_3(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112151103","Text":null,"Tag":null,"Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM707","MessageGroupNumber":null},"GeData":[{"SocietyHoldPlace":null,"Publicity":"ceshi4","Num":"","MeetingApprovedNo":"","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_4(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112151103","Text":null,"Tag":null,"Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM707","MessageGroupNumber":null},"GeData":[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi4","Num":"","MeetingApprovedNo":"202201110949","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_5(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{"GeData":[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi4","Num":"","MeetingApprovedNo":"202201110949","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_6(){
        Test.startTest();
		RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        String JsonMsg = '{}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
	}
    @isTest
    static void test_7(){
        Test.startTest();
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();

        OCM_Management_Province__c mp1 = new OCM_Management_Province__c();
        mp1.Name = '其他';
        mp1.Province__c = '北京市';
        mp1.Window1__c = getUser().Id;
        insert mp1;
        List<Application_for_Conference_Adjudication__c> afcList = [select id,MeetingApprovedNo__c from Application_for_Conference_Adjudication__c];
        // System.assertEquals(null, afcList);
        // System.assertEquals('202112161007', afcList[0].MeetingApprovedNo__c);
        StaticParameter.EscapeCampain =false;
        StaticParameter.shareToOSCMFlag = false; 
        Campaign cam = new Campaign();
        cam.Name = 'test campaign';
        cam.StartDate = Date.newInstance(2020,10,29);
        cam.EndDate = Date.newInstance(2020,11,29);
        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.cooperatorCompany__c = '1';
        // cam.CampaignStatus__c = '会议结束';
        cam.Num__c = '6666';
        cam.MeetingApprovedNo__c = '202112161007';
        cam.RecordTypeId = System.label.RecordType_CampaignService;
        // cam.OwnerId = getUser().Id;
        insert cam;
        List<Campaign> cammList = [select id,CampaignStatus__c from Campaign where Id = :cam.Id];

        // System.assertEquals(null, cammList);
        
        // String JsonMsg = '[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi0","Num":"","MeetingApprovedNo":"202112161007","Competitor":"ceshi3"}]';
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"202112151103","Text":null,"Tag":null,"Sender":"OBPM","Receiver":"SFDC","NumberOfRecord":"1","MessageType":"NFM707","MessageGroupNumber":null},"GeData":[{"SocietyHoldPlace":"ceshi5","Publicity":"ceshi4","Num":"6666","MeetingApprovedNo":"202112161007","Competitor":"ceshi3"}]}';
        req.requestURI = 'services/apexrest/NFM707/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;

        NFM707Rest.execute();
        Test.stopTest();
    }
}