Browse Source

1.支持检查API接口参数的正确性、完整性和有效性。 2.不同的API接口协议(如REST、SOAP、XML-RPC等),测试工具可提供对应的协议测试工具,确保API接口协议的正确性。

master
zhouyl 1 year ago
parent
commit
613884fdb7
  1. 102
      tp-functional/src/main/java/com/inscloudtech/functional/controller/FuncCarApiController.java
  2. 2
      tp-functional/src/main/java/com/inscloudtech/functional/service/IFuncCarApiService.java
  3. 42
      tp-functional/src/main/java/com/inscloudtech/functional/service/impl/FuncCarApiServiceImpl.java

102
tp-functional/src/main/java/com/inscloudtech/functional/controller/FuncCarApiController.java

@ -3,11 +3,18 @@ package com.inscloudtech.functional.controller;
import java.util.List;
import java.util.Arrays;
import com.inscloudtech.common.config.ProjectConfig;
import com.inscloudtech.common.utils.StringUtils;
import com.inscloudtech.common.utils.file.FileUtils;
import com.inscloudtech.functional.domain.FuncCarApi;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.inscloudtech.common.annotation.RepeatSubmit;
@ -36,8 +43,10 @@ public class FuncCarApiController extends BaseController {
private final IFuncCarApiService iFuncCarApiService;
private final ProjectConfig projectConfig;
/**
* 查询兼容可靠性测试系统-API接口兼容性测试工具列表
* 查询API接口在不同操作系统不同浏览器不同设备以及不同网络环境下的兼容性测试结果列表
*/
@SaCheckPermission("functional:CarApi:list")
@GetMapping("/list")
@ -45,31 +54,9 @@ public class FuncCarApiController extends BaseController {
return iFuncCarApiService.queryPageList(bo, pageQuery);
}
/**
* 导出兼容可靠性测试系统-API接口兼容性测试工具列表
*/
@SaCheckPermission("functional:CarApi:export")
@Log(title = "兼容可靠性测试系统-API接口兼容性测试工具", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(FuncCarApi bo, HttpServletResponse response) {
List<FuncCarApiVo> list = iFuncCarApiService.queryList(bo);
ExcelUtil.exportExcel(list, "兼容可靠性测试系统-API接口兼容性测试工具", FuncCarApiVo.class, response);
}
/**
* 获取兼容可靠性测试系统-API接口兼容性测试工具详细信息
*
* @param operId 主键
*/
@SaCheckPermission("functional:CarApi:query")
@GetMapping("/{operId}")
public R<FuncCarApiVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long operId) {
return R.ok(iFuncCarApiService.queryById(operId));
}
/**
* 兼容可靠性测试系统-API接口兼容性测试工具
* 测试API接口在不同操作系统不同浏览器不同设备以及不同网络环境下的兼容性
*/
@SaCheckPermission("functional:CarApi:add")
@Log(title = "兼容可靠性测试系统-API接口兼容性测试工具", businessType = BusinessType.INSERT)
@ -80,26 +67,63 @@ public class FuncCarApiController extends BaseController {
}
/**
* 修改兼容可靠性测试系统-API接口兼容性测试工具
* 模拟高并发高负载情况下的API接口性能和稳定性测试工具下载
*/
@SaCheckPermission("functional:CarApi:edit")
@Log(title = "兼容可靠性测试系统-API接口兼容性测试工具", businessType = BusinessType.UPDATE)
@GetMapping("/jmDownload")
public void jmDownload(HttpServletResponse response, HttpServletRequest request) {
String fileName = "apache-jmeter-5.6.3.zip";
try {
if (!FileUtils.checkAllowDownload(fileName)) {
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = projectConfig.getDownloadPath() + fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
// if (delete) {
// FileUtils.deleteFile(filePath);
// }
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 检查API接口参数的正确性完整性和有效性
*/
@SaCheckPermission("functional:CarApi:add")
@Log(title = "兼容可靠性测试系统-API接口兼容性测试工具", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody FuncCarApi bo) {
return toAjax(iFuncCarApiService.updateByBo(bo));
@PostMapping("/checkApi")
public R checkApi(@Validated(AddGroup.class) @RequestBody FuncCarApi bo) {
return R.ok(iFuncCarApiService.checkApi(bo));
}
/**
* 删除兼容可靠性测试系统-API接口兼容性测试工具
*
* @param operIds 主键串
* API接口协议如RESTSOAPXML-RPC等测试工具可提供对应的协议测试工具
*/
@SaCheckPermission("functional:CarApi:remove")
@Log(title = "兼容可靠性测试系统-API接口兼容性测试工具", businessType = BusinessType.DELETE)
@DeleteMapping("/{operIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] operIds) {
return toAjax(iFuncCarApiService.deleteWithValidByIds(Arrays.asList(operIds), true));
@GetMapping("/protocolToolDownload")
public void protocolToolDownload(HttpServletResponse response, HttpServletRequest request) {
String fileName = "apache-jmeter-5.6.3.zip";
try {
if (!FileUtils.checkAllowDownload(fileName)) {
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = projectConfig.getDownloadPath() + fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
// if (delete) {
// FileUtils.deleteFile(filePath);
// }
} catch (Exception e) {
e.printStackTrace();
}
}
}

2
tp-functional/src/main/java/com/inscloudtech/functional/service/IFuncCarApiService.java

@ -45,4 +45,6 @@ public interface IFuncCarApiService {
* 校验并批量删除兼容可靠性测试系统-API接口兼容性测试工具信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
String checkApi(FuncCarApi bo);
}

42
tp-functional/src/main/java/com/inscloudtech/functional/service/impl/FuncCarApiServiceImpl.java

@ -2,6 +2,8 @@ package com.inscloudtech.functional.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.*;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.inscloudtech.common.core.page.TableDataInfo;
import com.inscloudtech.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -114,7 +116,6 @@ public class FuncCarApiServiceImpl implements IFuncCarApiService {
}
}
}
HttpResponse httpResponse = request.execute();
bo.setResponseTime(System.currentTimeMillis() - start);
bo.setJsonResult(httpResponse.body());
@ -148,4 +149,43 @@ public class FuncCarApiServiceImpl implements IFuncCarApiService {
return baseMapper.deleteBatchIds(ids) > 0;
}
@Override
public String checkApi(FuncCarApi bo) {
HttpRequest request;
if(StringUtils.isEmpty(bo.getRequestMethod())){
request = HttpUtil.createRequest(Method.GET, bo.getApiUrl());
}else {
if(bo.getRequestMethod().toLowerCase().contains("post")){
request = HttpUtil.createRequest(Method.POST, bo.getApiUrl());
}else {
request = HttpUtil.createRequest(Method.GET, bo.getApiUrl());
}
}
request.header(Header.CONNECTION,"keep-alive");
request.header(Header.ACCEPT,"*/*");
request.header(Header.CONTENT_TYPE,"application/json; charset=UTF-8");
request.header(Header.CACHE_CONTROL,"max-age=0");
request.header(Header.USER_AGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) ");
String body = "";
try {
body = request.execute().body();
JSONObject entries = JSONUtil.parseObj(body);
if(entries.containsKey("code")){
if(entries.get("code") == null){
body = "api接口返回非标准格式,无法检查!接口返回结果【" +body+ "】";
}else if(entries.getStr("code").equals("500")){
body = "api接口参数异常,接口返回结果【" +body+ "】";
}else if(entries.getStr("code").equals("200")){
body = "api接口调用正常,接口返回结果【" +body+ "】";
}
}else {
body = "api接口返回非标准格式,无法检查!接口返回结果【" +body+ "】";
}
}catch (Exception e){
body = "api接口调用异常:"+ e.getMessage();
}
return body;
}
}
Loading…
Cancel
Save