Exemplo n.º 1
0
 /**
  * 执行数据批次的更新操作,id为批次id
  *
  * @param caseId
  * @param id
  * @param expectData
  * @return
  */
 @RequestMapping(value = "/INTERFACE_CASE/update/{cid}/{id}", method = RequestMethod.POST)
 public String updateBatchData(
     @PathVariable Integer cid, @PathVariable Integer id, String expectData) {
   InterfaceBatchDataBean iDataBean = inBatchDataService.getInBatchBean(id);
   iDataBean.setExpectData(expectData);
   inBatchDataService.updateInBatch(iDataBean);
   System.out.println(expectData);
   return "redirect:/data/INTERFACE_CASE/list/" + cid;
 }
Exemplo n.º 2
0
 /**
  * 执行添加操作
  *
  * @param caseId
  * @param expectData
  * @return
  */
 @RequestMapping(value = "/INTERFACE_CASE/add/{caseId}", method = RequestMethod.POST)
 public String addBatch(@PathVariable Integer caseId, String expectData) {
   CaseBean caseBean = caseService.getCaseBean(caseId);
   InterfaceBatchDataBean interBatchDataBean = new InterfaceBatchDataBean();
   interBatchDataBean.setCaseBean(caseBean);
   interBatchDataBean.setExpectData(expectData);
   inBatchDataService.addInBatch(interBatchDataBean);
   return "redirect:/data/INTERFACE_CASE/list/" + caseId;
 }
Exemplo n.º 3
0
 @RequestMapping(
     value = "/export/{id}",
     method = RequestMethod.POST,
     produces = "text/plain;charset=UTF-8")
 public @ResponseBody String exportData(
     @PathVariable Integer id, HttpServletRequest req, Model model) {
   CaseBean caseBean = caseService.getCaseBean(id);
   String fileName = GetNow.getCurrentTime("yyyyMMddHHmmss") + "_" + caseBean.getCaseName();
   String filePath =
       req.getSession().getServletContext().getRealPath("/resources/upload/")
           + "/"
           + fileName
           + ".xlsx";
   SheetContentDTO sheetDTO = new SheetContentDTO();
   ExcelUtil excelUtil = new ExcelUtil();
   List<String[]> parameters = new ArrayList<String[]>();
   List<InterfaceBatchDataBean> ibatchDataList = inBatchDataService.getInBatchList(id);
   sheetDTO.setCaseName(caseBean.getCaseName());
   sheetDTO.setCaseId(id + "");
   String[] paramName = null;
   for (InterfaceBatchDataBean batchData : ibatchDataList) {
     List<InterfaceDataBean> idataBeanList = inDataBeanService.getDataBeans(batchData.getId());
     String[] paramContent = new String[idataBeanList.size() + 1];
     paramName = new String[idataBeanList.size() + 1];
     paramName[0] = "期望值\\参数名";
     paramContent[0] = batchData.getExpectData();
     for (int i = 0; i < idataBeanList.size(); i++) {
       paramName[i + 1] = idataBeanList.get(i).getDataName();
       paramContent[i + 1] = idataBeanList.get(i).getDataContent();
     }
     parameters.add(paramContent);
   }
   sheetDTO.setParamNames(paramName);
   sheetDTO.setParameters(parameters);
   excelUtil.setExportExcelPath(filePath);
   try {
     excelUtil.exportExcel(sheetDTO);
     String fileUrl =
         "http://"
             + req.getServerName()
             + ":"
             + req.getServerPort()
             + "/phoenix_web/resources/upload/"
             + fileName
             + ".xlsx";
     return JSON.toJSONString(
         new AjaxObj(
             1,
             "导出接口用例[ "
                 + caseBean.getCaseName()
                 + " ]的数据成功!<br>点击下载:<a href='"
                 + fileUrl
                 + "'>"
                 + fileUrl
                 + "</a>",
             fileName));
   } catch (Exception e) {
     return JSON.toJSONString(
         new AjaxObj(0, "导出接口用例[ " + caseBean.getCaseName() + " ]的数据失败!<br>" + e.getCause()));
   }
 }