/** * 根据指定的key列表,从map中取出新的map * * @param mapTmpList * @param keyList * @return List<Map<String, String>> */ private static List<Map<String, String>> getMapByKeyList( List<Map<String, String>> mapTmpList, List<String> keyList) { List<Map<String, String>> mapList = new ArrayList<Map<String, String>>(); Map<String, String> mapTmp; if (null == keyList || keyList.size() < 1) { log.error("要获取的列信息为空,请检查"); return mapList; } if (null == mapTmpList || mapTmpList.size() < 1) { return mapList; } for (int i = 0; i < mapTmpList.size(); i++) { // 处理多条查询结果 mapTmp = new TreeMap<>(); for (int j = 0; j < keyList.size(); j++) { // 获取指定列信息 String key = keyList.get(j); String value = StringUtil.getValueFromMapByKey(mapTmpList.get(i), key); mapTmp.put(key, value); } mapList.add(mapTmp); } return mapList; }
/** * 根据header url发起get请求 * * @param headers * @param url * @return ResponseInfo */ public ResponseInfo get(Map<String, String> headers, String url) { ResponseInfo resInfo = new ResponseInfo(); if (StringUtil.IsNullOrEmpty(url)) { log.error("url为空"); resInfo.setResBodyInfo("url为空"); return resInfo; } httpGet = new HttpGet(url); httpGet = setHttpGetHeader(httpGet, headers); return get(httpGet); }
/** * 设置发送请求的headers,url,str信息,发送post请求,得到返回的字符串结果集 * * @param headers * @param url * @param str * @return ResponseInfo */ public ResponseInfo post(TreeMap<String, String> headers, String url, String str) { ResponseInfo resInfo = new ResponseInfo(); if (StringUtil.IsNullOrEmpty(url)) { log.error("url为空"); resInfo.setResBodyInfo("url为空"); return resInfo; } httpPost = new HttpPost(url); httpPost = setHttpPostHeaderAndParams(httpPost, headers, null); return post(httpPost, str); }
/** * get方式下载文件,以字符串方式显示 * * @param headers * @param url * @return String */ public String getFile(Map<String, String> headers, String url, String enCoding) { if (StringUtil.IsNullOrEmpty(enCoding)) enCoding = "UTF-8"; httpGet = new HttpGet(url); httpGet = setHttpGetHeader(httpGet, headers); try { return new String(getFile(httpGet), enCoding); } catch (UnsupportedEncodingException e) { log.error("getFile执行异常207:"); log.error(e.getMessage()); return ""; } }
/** * @param pathName * @param sheetIndex */ private void getTestCaseFromExcel(String pathName, String sheetName) { // 记录读取到的用例数据信息 ReadCaseFromExcel readCase = new ReadCaseFromExcel(pathName, sheetName); // 读取表表信息 url = readCase.readUrl(); httpMethod = readCase.readHttpMethod(); argcount = readCase.readArgCount(); // 参与sign计算的参数个数 this.cookie = readCase.readCookie(); String[] argKey = readCase.readArgKey(); // 获取参数key // 设置测试集名称,Excel中未存储,从判断传入的path为excel时设置 // casesetName=readcase(); // 获取用例数据 for (int j = IftConf.paramStartRow; j < readCase.getRowNum(); j++) { IftTestCase tempcase = new IftTestCase(); tempcase.setArgCount(getArgcount()); tempcase.setHttpMethod(getHttpMethod()); tempcase.setUrl(getUrl()); tempcase.setCookie(this.cookie); // 读取【j+1】行的数据 String[] argValue = readCase.readArgValue(j); // System.out.print("行:"+j+" 参数个数"+argValue.length+argValue[1]+"\n"); if (!argValue[IftConf.isRunCol].equals("Y")) { continue; } else { // 把数据和标题一一对应存入LinkedHashMap有序键值对中 LinkedHashMap<String, String> mycase = new LinkedHashMap<String, String>(); for (int i = 0; i < argKey.length; i++) { // 判断此条记录是否有cookie参数,如果有且不为空替换全局cookie if (null != argValue[i] && argKey[i].equals("cookie") && argValue[i].length() > 0) { String dependCookie = (String) (IftConf.DependPara).get("cookie"); // 重新赋值value tempcase.setCookie( StringUtil.paramReplace( argValue[i], dependCookie)); // cookie参数依赖(将之前接口获取的cookie值进行替换) } mycase.put(argKey[i], argValue[i]); } arrCase.add(mycase); tempcase.setCaseMap(mycase); tempcase.setCaseId(mycase.get("CaseID")); tempcase.setTestPoint(mycase.get("TestPoint")); } this.testCase.add(tempcase); } }
/** * 按指定的查询条件和表名,查询表中所有数据,返回Map中key对应的列 * * @param tablename * @param wherestr * @param expMap * @return List<Map<String, String>> */ public static List<Map<String, String>> getMapFromSql( String tablename, String wherestr, Map<String, String> expMap) { List<String> keyList = StringUtil.getKeyListFromMap(expMap); return getMapFromSql(tablename, wherestr, keyList); }