@isTest
private class LoanerApplicationWebServiceTest {
	static Product2 prd1;
    static Product2 prd2;
    static Account acc;
    static Account dealer;
    static Contact core;
    static User testUser;
    static Asset asset;
	static void setupTestData() {

		OlympusCalendar__c oc1 = new OlympusCalendar__c(Date__c = Date.today().addDays(1), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc2 = new OlympusCalendar__c(Date__c = Date.today().addDays(2), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc3 = new OlympusCalendar__c(Date__c = Date.today().addDays(3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc4 = new OlympusCalendar__c(Date__c = Date.today().addDays(4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc5 = new OlympusCalendar__c(Date__c = Date.today().addDays(5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc6 = new OlympusCalendar__c(Date__c = Date.today().addDays(6), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc7 = new OlympusCalendar__c(Date__c = Date.today().addDays(7), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc8 = new OlympusCalendar__c(Date__c = Date.today().addDays(8), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc9 = new OlympusCalendar__c(Date__c = Date.today().addDays(9), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc10 = new OlympusCalendar__c(Date__c = Date.today().addDays(10), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc11 = new OlympusCalendar__c(Date__c = Date.today().addDays(11), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc12 = new OlympusCalendar__c(Date__c = Date.today().addDays(12), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc13 = new OlympusCalendar__c(Date__c = Date.today().addDays(-1), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc14 = new OlympusCalendar__c(Date__c = Date.today().addDays(-2), ChangeToHoliday__c=true, ChangeToWorkday__c=false);
        OlympusCalendar__c oc15 = new OlympusCalendar__c(Date__c = Date.today().addDays(-3), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc16 = new OlympusCalendar__c(Date__c = Date.today().addDays(-4), ChangeToHoliday__c=false, ChangeToWorkday__c=true);
        OlympusCalendar__c oc17 = new OlympusCalendar__c(Date__c = Date.today().addDays(-5), ChangeToHoliday__c=false, ChangeToWorkday__c=true);

        insert new OlympusCalendar__c[] {oc1,oc2,oc3,oc4,oc5,oc6,oc7,oc8,oc9,oc10,oc11,oc12,oc13,oc14,oc15,oc16,oc17};

		List<RecordType> dealerIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        if (dealerIE.size() == 0) {
            return;
        }
        List<RecordType> olyCompany = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'OlympusCompany'];
        if (olyCompany.size() == 0) {
            return;
        }

        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        List<RecordType> loa_number = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_数量管理'];
        if (loa_number.size() == 0) {
            return;
        }

        //代理商用户
        List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        Profile prof = [select Id from Profile where Name ='SSBG DEALER IE'];
        dealer = new Account();
        dealer.Name = 'test dealer';
        dealer.RecordTypeId = rectDealer[0].Id;
        dealer.ProductSegment__c = 'IE';
        dealer.PostCode__c='000000';
        insert dealer;
        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=dealer.id);
        insert core;
        testUser = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser01@prectech.com');
        insert testUser;

        //样机客户
        acc = new Account();
        acc.Name = 'test dealer';
        acc.RecordTypeId = olyCompany[0].Id;
        acc.ProductSegment__c = 'IE';
        acc.PostCode__c='000000';
        insert acc;

		// 产品
        prd1 = new Product2();
        prd1.Product_ECCode__c      = 'testSBG001';
        prd1.ProductCode            = 'testSBG001';
        prd1.Name                   = 'testSBG001';
        prd1.IsActive               = true;

        prd2 = new Product2();
        prd2.Product_ECCode__c      = 'testSBG002';
        prd2.ProductCode            = 'testSBG002';
        prd2.Name                   = 'testSBG002';
        prd2.IsActive               = true;
        insert new Product2[] {prd1, prd2};

        // 保有设备 (数量管理)
        asset = new Asset();
        asset.RecordTypeId = loa_number[0].Id;
        asset.SerialNumber = 'asset';
        asset.Name = 'asset';
        asset.AccountId = acc.Id;
        asset.Product2Id = prd2.Id;
        asset.Quantity = 1;
        asset.Status = '在库';
        asset.Equipment_Type__c = 'IE';
        asset.loaner_place__c = '广州办';
        asset.total_number__c = 20;
        asset.Remarks2__c = 'asset';

        // 保有设备 (个体管理)
        Asset assetC1 = new Asset();
        assetC1.RecordTypeId = loa_individual[0].Id;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = acc.Id;
        assetC1.Product2Id = prd1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '在库';
        assetC1.Equipment_Type__c = 'IE';
        assetC1.loaner_place__c = '北京酒仙桥';
        assetC1.Remarks2__c = 'assetC1';
        
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        insert new Asset[] {asset,assetC1};
	}
	//出库指示
	@isTest static void loanIndicationTest() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        LoanerApplicationWebService.loanIndication('111111111111111');
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '申请中';
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.pickup_time__c = Date.today().addDays(2);
        insert loanerApp;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        update loanerApp;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);

        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '已批准';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.loanIndication(loanerApp.Id);
	}
	@isTest static void sendOutAllTest01() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        System.Test.startTest();
        LoanerApplicationWebService.sendOutAll('111111111111111');
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        insert loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);

        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '出库前已检测';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.Status__c = '已出库指示';
       	update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.Status__c = '出库前已检测';
        update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        loanerApp.pickup_time__c = Date.today();
        update loanerApp;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
        System.Test.stopTest();

	}
	@isTest static void sendOutAllTest02() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '出库前已检测';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '出库前已检测';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        LoanerApplicationWebService.sendOutAll(loanerApp.Id);
	}

	@isTest static void installConfirmTest() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        LoanerApplicationWebService.installConfirm('111111111');
        LoanerApplicationWebService.installConfirm(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        update loanerApp;
        LoanerApplicationWebService.installConfirm(loanerApp.Id);

        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
	}

	@isTest static void sendBackAllTest() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        LoanerApplicationWebService.sendBackAll('111111111');
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        loanerApp.Return_Track_Company__c = '11111';
        loanerApp.Return_Track_Number__c = '11111';
        loanerApp.Return_Trake_Staff__c = '11111';
        update loanerApp;
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);

	}
    @isTest static void sendBackAllTest1() {
        setupTestData();

        List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'NDT'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'NDT';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
        loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'NDT';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '培训';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        LoanerApplicationWebService.sendBackAll('111111111');
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);
        loanerApp.Status__c = '申请者已收货';
        loanerApp.Return_Track_Company__c = '11111';
        loanerApp.Return_Track_Number__c = '11111';
        loanerApp.Return_Trake_Staff__c = '11111';
        loanerApp.loaner_manage_place__c = '北京酒仙桥';
        loanerApp.loaner_return__c = true;
        update loanerApp;
        LoanerApplicationWebService.sendBackAll(loanerApp.Id);

    }

	@isTest static void splitLoanerApplicationTest() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '已批准';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-02';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = asset.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;
        System.Test.startTest();

        LoanerApplicationWebService.splitLoanerApplication('111111111');
        loanerApp.Status__c = '申请者已收货';
        update loanerApp;

        LoanerApplicationWebService.splitLoanerApplication(loanerApp.Id);
        loanerApp.Status__c = '销售担当批准';
        update loanerApp;
        LoanerApplicationWebService.splitLoanerApplication(loanerApp.Id);
        System.Test.stopTest();

	}

	@isTest static void cancelLoanerApplicationTest() {
		setupTestData();

		List<RecordType> rectLapp = [select Id from RecordType where IsActive = true and SobjectType = 'loaner_application__c' and Name = 'IE'];
        if (rectLapp.size() == 0) {
            return;
        }
        List<RecordType> loa_individual = [select Id from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '样机_个体管理'];
        if (loa_individual.size() == 0) {
            return;
        }
        // 保有设备 (个体管理)
        Asset assetC2 = new Asset();
        assetC2.RecordTypeId = loa_individual[0].Id;
        assetC2.SerialNumber = 'assetC2';
        assetC2.Name = 'assetC2';
        assetC2.AccountId = acc.Id;
        assetC2.Product2Id = prd1.Id;
        assetC2.Quantity = 1;
        assetC2.Status = '在库';
        assetC2.Equipment_Type__c = 'IE';
        assetC2.loaner_place__c = '北京酒仙桥';
        assetC2.Remarks2__c = 'assetC2';
        insert assetC2;
		loaner_application__c loanerApp = new loaner_application__c();
        loanerApp.Name = 'TESTYJ0001';
        loanerApp.Approval_Step__c = 1;
        loanerApp.Status__c = '申请中';
        loanerApp.Rental_Start_Date__c = Date.today();
        loanerApp.Rental_End_Date__c = Date.today();
        loanerApp.Loaner_Ser__c = 'test';
        loanerApp.Equipment_Type__c = 'IE';
        loanerApp.RecordTypeId = rectLapp[0].Id;
        loanerApp.Demo_purpose__c = '演示';
        loanerApp.Request_shipping_Date__c = Date.today();
        loanerApp.Request_return_Date__c = Date.today();
        loanerApp.delivery_company__c = '111111111';
        loanerApp.Tracking_Number__c = '22222222';
        loanerApp.Return_to_wh_staff__c = testUser.Id;
        loanerApp.pickup_time__c = Date.today().addDays(2);
        insert loanerApp;
        loaner_application_detail__c loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-01';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = assetC2.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        loanerAppDet = new loaner_application_detail__c();
        loanerAppDet.RAESD_Status__c = '申请者已收货';
        loanerAppDet.Name = 'TESTYJ0001-02';
        loanerAppDet.loaner_application__c = loanerApp.Id;
        loanerAppDet.LOANER__c = asset.Id;
        loanerAppDet.Allocate_Date__c = Date.today();
        insert loanerAppDet;

        LoanerApplicationWebService.cancelLoanerApplication('111111111');
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);
        loanerApp.Status__c = '已批准';
        update loanerApp;
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);
        loanerApp.Cancel_Reason__c = 'test';
        update loanerApp;
        LoanerApplicationWebService.cancelLoanerApplication(loanerApp.Id);

	}
}