package com.xiaomai.utils;

import com.alibaba.fastjson.JSONObject;
import com.xiaomai.jdbc.dao.DataDao;
import com.xiaomai.jdbc.entity.ApiInfo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.Assert;

/**
 * 获取requestParamter
 *
 * @Author laosy
 * @Date 2020/11/17  20:22
 */
public class ParamterTemplate {
    public static JSONObject getApiParamterTemplate(String apiModule, String apiName) {
       /* Assert.assertNotNull(apiModule, "必要的api信息不存在！");
        Properties prop = CommUtil.getconfig();
        JsonAndFile fileHandle = new JsonAndFile();

        String apiModulePath = prop.getProperty(apiModule);
        // 获取接口模块参数
        String fileParam = fileHandle.readTxtFile(System.getProperty("user.dir") + apiModulePath);
        Assert.assertNotNull(fileParam, "必要的API模块信息未找到，请检查api模块文件路径！");

        JSONObject api = (JSONObject) JSON.parseObject(fileParam).get(apiName);
        Assert.assertNotNull(api, "必要的API接口信息未找到，请检查apiName信息！");
        if (api.containsKey("requestParamter")) {
            *//* executionApi.setRequestParamterTemplate(api.getString("requestParamter"));*//*
        }

        return api.getJSONObject("requestParamter");*/
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

        DataDao dataDao = (DataDao) applicationContext.getBean("dataDao");
        ApiInfo apiInfo = dataDao.getApiInfo(apiModule, apiName);
        Assert.assertNotNull(apiInfo, "接口信息不存在!");

        return JSONObject.parseObject(apiInfo.getRequestParameter());
    }
}
