@isTest
private class MaintenanceContractWebServiceTest {

    @isTest static void test_method_one() {
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;

        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];

        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        insert contract;

        // 维修合同を作成する
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract';
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dep.Id;
        contract1.Maintenance_Contract_No__c = 'contact1';
        contract1.Contract_Conclusion_Date__c = Date.today();
        contract1.Inspection_Time__c = '4';
        contract1.Contract_End_Date__c = Date.today().addMonths(+28);
        contract1.Contract_Start_Date__c = Date.today();
        contract1.Contract_Range__c = Decimal.valueOf('28');
        insert contract1;

        List<String> mcidList = new  List<String>();
        mcidList.add(contract1.Id);
        MaintenanceContractWebService.up2sap(contract.Id);
        MaintenanceContractWebService.up2sap(contract1.Id);

        delete contract;
        MaintenanceContractWebService.up2sap(contract.Id);
        MaintenanceContractWebService.Check_plan(mcidList);
    }

    @isTest
    static void test_method_two() {
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;

        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];

        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        insert contract;

        // 维修合同を作成する
        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract';
        contract1.Hospital__c = hospital.Id;
        contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dep.Id;
        contract1.Maintenance_Contract_No__c = 'contact1';
        contract1.Contract_Conclusion_Date__c = Date.today();
        contract1.Inspection_Time__c = '1';
        contract1.Contract_End_Date__c = Date.today().addMonths(+20);
        contract1.Contract_Start_Date__c = Date.today();
        contract1.Contract_Range__c = Decimal.valueOf('20');
        insert contract1;
        List<String> mcidList = new  List<String>();
        mcidList.add(contract1.Id);

        MaintenanceContractWebService.up2sap(contract.Id);
        MaintenanceContractWebService.up2sap(contract1.Id);

        delete contract;
        MaintenanceContractWebService.up2sap(contract.Id);
        MaintenanceContractWebService.Check_plan(mcidList);
    }

}