refactor(接口测试): 删除ESB功能
This commit is contained in:
parent
3489e6e306
commit
f4be75de5f
|
@ -1,202 +0,0 @@
|
|||
package io.metersphere.api.dto.automation;
|
||||
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* //ESB数据格式
|
||||
*
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/15 4:37 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class EsbDataStruct {
|
||||
private String uuid;
|
||||
private String name;
|
||||
private String value;
|
||||
private String type;
|
||||
private String systemName;
|
||||
private String contentType;
|
||||
private boolean required;
|
||||
private String description;
|
||||
private List<EsbDataStruct> children;
|
||||
private String status = StringUtils.EMPTY;
|
||||
|
||||
public void init() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.systemName = StringUtils.EMPTY;
|
||||
this.description = StringUtils.EMPTY;
|
||||
this.value = StringUtils.EMPTY;
|
||||
this.required = true;
|
||||
this.contentType = StringUtils.EMPTY;
|
||||
this.type = StringUtils.EMPTY;
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean initDefaultData(String name, String typeLength, String chineseName, String desc) {
|
||||
this.init();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return false;
|
||||
}
|
||||
if (typeLength == null) {
|
||||
typeLength = StringUtils.EMPTY;
|
||||
} else {
|
||||
typeLength = typeLength.trim();
|
||||
typeLength = typeLength.toLowerCase();
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
|
||||
if (typeLength.startsWith(PropertyConstant.STRING)) {
|
||||
this.type = PropertyConstant.STRING;
|
||||
String lengthStr = typeLength.substring(6);
|
||||
if (lengthStr.startsWith("(") && lengthStr.endsWith(")")) {
|
||||
try {
|
||||
int length = Integer.parseInt(lengthStr.substring(1, lengthStr.length() - 1));
|
||||
this.contentType = String.valueOf(length);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
} else if (typeLength.startsWith(PropertyConstant.ARRAY)) {
|
||||
this.type = PropertyConstant.ARRAY;
|
||||
} else {
|
||||
this.type = PropertyConstant.OBJECT;
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(desc)) {
|
||||
desc = StringUtils.EMPTY;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(chineseName)) {
|
||||
this.description = chineseName + ":" + desc;
|
||||
} else {
|
||||
this.description = desc;
|
||||
}
|
||||
|
||||
if (this.description.endsWith(":")) {
|
||||
this.description = this.description.substring(0, this.description.length() - 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public EsbDataStruct copy(boolean copyChildren) {
|
||||
EsbDataStruct returnObj = new EsbDataStruct();
|
||||
returnObj.name = this.name;
|
||||
returnObj.value = this.value;
|
||||
returnObj.type = this.type;
|
||||
returnObj.systemName = this.systemName;
|
||||
returnObj.contentType = this.contentType;
|
||||
returnObj.required = this.required;
|
||||
returnObj.description = this.description;
|
||||
if (copyChildren) {
|
||||
returnObj.children = this.children;
|
||||
} else {
|
||||
returnObj.children = new ArrayList<>();
|
||||
}
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
public Element genXmlElementByChildren(Element document) {
|
||||
this.name = this.name.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
.replace("\"", """).replace("©", "'");
|
||||
if (StringUtils.isEmpty(this.name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Element element = null;
|
||||
try {
|
||||
element = document.addElement(this.name);
|
||||
if (StringUtils.equalsAnyIgnoreCase(type, PropertyConstant.STRING, PropertyConstant.ARRAY)) {
|
||||
String attrString = StringUtils.EMPTY;
|
||||
if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.STRING)) {
|
||||
attrString = "s," + contentType;
|
||||
} else if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.ARRAY)) {
|
||||
attrString = "a," + contentType;
|
||||
}
|
||||
element.addAttribute("attr", attrString);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
||||
if (element != null) {
|
||||
if (this.children == null || this.children.isEmpty()) {
|
||||
if (this.value == null) {
|
||||
this.value = StringUtils.EMPTY;
|
||||
}
|
||||
element.addText(this.value);
|
||||
} else {
|
||||
for (EsbDataStruct child : children) {
|
||||
child.genXmlElementByChildren(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public Element genXmlElementByDocument(Document document) {
|
||||
this.name = this.name.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
.replace("\"", """).replace("©", "'");
|
||||
if (StringUtils.isEmpty(this.name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Element element = null;
|
||||
try {
|
||||
element = document.addElement(this.name);
|
||||
if (StringUtils.equalsAnyIgnoreCase(type, PropertyConstant.STRING, PropertyConstant.ARRAY)) {
|
||||
String attrString = StringUtils.EMPTY;
|
||||
if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.STRING)) {
|
||||
attrString = "s," + contentType;
|
||||
} else if (StringUtils.equalsIgnoreCase(this.type, PropertyConstant.ARRAY)) {
|
||||
attrString = "a," + contentType;
|
||||
}
|
||||
element.addAttribute("attr", attrString);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
||||
if (element != null) {
|
||||
if (this.children == null || this.children.isEmpty()) {
|
||||
element.addText(this.value);
|
||||
} else {
|
||||
for (EsbDataStruct child : children) {
|
||||
child.genXmlElementByChildren(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<String> getNameDeep() {
|
||||
List<String> returnList = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(this.name)) {
|
||||
returnList.add(this.name);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(this.children)) {
|
||||
for (EsbDataStruct child : this.children) {
|
||||
List<String> itemNameList = child.getNameDeep();
|
||||
for (String itemName : itemNameList) {
|
||||
if (!returnList.contains(itemName)) {
|
||||
returnList.add(itemName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
}
|
|
@ -57,9 +57,6 @@ public class SaveApiDefinitionRequest {
|
|||
|
||||
private String tags;
|
||||
|
||||
//ESB参数。 可为null
|
||||
private String esbDataStruct;
|
||||
private String backEsbDataStruct;
|
||||
private String backScript;
|
||||
|
||||
// 创建新版本时用到的
|
||||
|
|
|
@ -24,8 +24,4 @@ public class SaveApiTestCaseRequest extends ApiTestCase {
|
|||
private List<String> follows;
|
||||
|
||||
private String versionId;
|
||||
|
||||
//ESB参数。 可为null
|
||||
private String esbDataStruct;
|
||||
private String backEsbDataStruct;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.api.dto.definition.request.sampler;
|
||||
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
|
||||
import io.metersphere.api.dto.definition.request.ElementUtil;
|
||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||
|
@ -79,11 +78,6 @@ public class MsTCPSampler extends MsTestElement {
|
|||
private String jsonDataStruct;
|
||||
private String rawDataStruct;
|
||||
private boolean customizeReq;
|
||||
/**
|
||||
* 新加两个参数,场景保存/修改时需要的参数。不会传递JMeter,只是用于最后的保留。
|
||||
*/
|
||||
private List<EsbDataStruct> esbDataStruct;
|
||||
private List<EsbDataStruct> backEsbDataStruct;
|
||||
|
||||
@Override
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package io.metersphere.api.parse.api;
|
||||
|
||||
import io.metersphere.api.parse.api.ms.NodeTree;
|
||||
import io.metersphere.api.dto.mock.config.MockConfigImportDTO;
|
||||
import io.metersphere.api.parse.api.ms.NodeTree;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ApiDefinitionImport {
|
||||
|
@ -20,9 +18,6 @@ public class ApiDefinitionImport {
|
|||
// 新版本带用例导出
|
||||
private List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
||||
|
||||
//ESB文件导入的附属数据类
|
||||
private Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap;
|
||||
|
||||
//Mock数据相关
|
||||
private List<MockConfigImportDTO> mocks;
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ public class ApiDefinitionImportParserFactory {
|
|||
return new Swagger2Parser();
|
||||
} else if (StringUtils.equals(ApiImportPlatform.Har.name(), platform)) {
|
||||
return new HarParser();
|
||||
} else if (StringUtils.equals(ApiImportPlatform.ESB.name(), platform)) {
|
||||
return new ESBParser();
|
||||
} else if (StringUtils.equals(ApiImportPlatform.Jmeter.name(), platform)) {
|
||||
return new JmeterDefinitionParser();
|
||||
}
|
||||
|
|
|
@ -1,775 +0,0 @@
|
|||
package io.metersphere.api.parse.api;
|
||||
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.parse.api.esb.ESBExcelSheetInfo;
|
||||
import io.metersphere.api.parse.api.esb.EsbExcelDataStruct;
|
||||
import io.metersphere.api.parse.api.esb.EsbSheetDataStruct;
|
||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.commons.constants.RequestTypeConstants;
|
||||
import io.metersphere.service.definition.EsbApiParamService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.swagger.models.Model;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/10 11:14 上午
|
||||
* @Description
|
||||
*/
|
||||
public class ESBParser extends EsbAbstractParser {
|
||||
|
||||
private Map<String, Model> definitions = null;
|
||||
|
||||
/**
|
||||
* 导出模板
|
||||
*
|
||||
* @param response
|
||||
* @param fileName
|
||||
*/
|
||||
public static void export(HttpServletResponse response, String fileName) {
|
||||
|
||||
XSSFWorkbook wb = null;
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
wb = getTemplate();
|
||||
out = response.getOutputStream();
|
||||
response.reset();
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()) + ".xlsx");
|
||||
wb.write(out);
|
||||
wb.close();
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
if (wb != null) {
|
||||
try {
|
||||
wb.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static XSSFWorkbook getTemplate() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFFont font = workbook.createFont();
|
||||
font.setFontHeightInPoints((short) 9);
|
||||
Map<String, XSSFCellStyle> cellStyleMap = createCellStyle(workbook);
|
||||
XSSFSheet headSheet = workbook.createSheet("公共报文头");
|
||||
generateSheet(headSheet, font, cellStyleMap);
|
||||
XSSFSheet bodySheet = workbook.createSheet("接口报文信息");
|
||||
generateSheet(bodySheet, font, cellStyleMap);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
private static Map<String, XSSFCellStyle> createCellStyle(XSSFWorkbook workbook) {
|
||||
Map<String, XSSFCellStyle> cellStype = new HashMap<>();
|
||||
short[] colorIndexArr = {IndexedColors.LIGHT_GREEN.getIndex(), IndexedColors.ORCHID.getIndex(), IndexedColors.YELLOW.getIndex()};
|
||||
for (short colorIndex : colorIndexArr) {
|
||||
XSSFCellStyle style = workbook.createCellStyle();
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
|
||||
String name = StringUtils.EMPTY;
|
||||
if (colorIndex == IndexedColors.LIGHT_GREEN.getIndex()) {
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 255, 204), null));
|
||||
name = "green";
|
||||
} else if (colorIndex == IndexedColors.ORCHID.getIndex()) {
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(151, 50, 101), null));
|
||||
name = "pop";
|
||||
} else if (colorIndex == IndexedColors.YELLOW.getIndex()) {
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 153), null));
|
||||
name = "yellow";
|
||||
} else {
|
||||
name = PropertyConstant.DEFAULT;
|
||||
}
|
||||
cellStype.put(name, style);
|
||||
}
|
||||
return cellStype;
|
||||
}
|
||||
|
||||
private static void generateSheet(XSSFSheet sheet, XSSFFont font, Map<String, XSSFCellStyle> cellStyleMap) {
|
||||
if (sheet == null) {
|
||||
return;
|
||||
}
|
||||
sheet.setColumnWidth(0, 4000);
|
||||
sheet.setColumnWidth(1, 4000);
|
||||
sheet.setColumnWidth(2, 4000);
|
||||
sheet.setColumnWidth(3, 4000);
|
||||
sheet.setColumnWidth(4, 880);
|
||||
sheet.setColumnWidth(5, 4000);
|
||||
sheet.setColumnWidth(6, 4000);
|
||||
sheet.setColumnWidth(7, 4000);
|
||||
sheet.setColumnWidth(8, 4000);
|
||||
sheet.setColumnWidth(9, 4000);
|
||||
|
||||
/**
|
||||
* 模版生成:
|
||||
* 字体大小:9
|
||||
* row1: 1交易码 2交易名称 (head的话是5)6(紫色[pop]背景空白单元格,下同) 7服务名称 8服务场景
|
||||
* row2: 1.请输入交易码(必填) 2请输入交易名称(必填) 7请输入服务名称(如果不填,则以交易名称为主) 8请输入服务场景(选填)
|
||||
* row3: 合并7-10单元格,输入:请输入系统名称 背景色:黄色[yellow]
|
||||
* row4: 1.英文名称2.中文名称3.数据类型/长度4.是否必输5.备注 7.英文名称8.数据类型/长度9.中文名称 10备注 背景色:黄色
|
||||
* row5: 整行都是青色【green】,1:输入
|
||||
* row6: 3:请输入STRING(具体长度) 或 ARRAY; 8:同3
|
||||
* row7:无
|
||||
* row8: 整行都是青色,1:输出
|
||||
* row9: 3:请输入STRING(具体长度) 或 ARRAY; 8:同3
|
||||
*/
|
||||
XSSFRow row1 = sheet.createRow(0);
|
||||
setCellValue("交易码", row1.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("交易名称", row1.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(4), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("服务名称", row1.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("服务场景", row1.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row1.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
|
||||
|
||||
XSSFRow row2 = sheet.createRow(1);
|
||||
setCellValue("请输入交易码(必填)", row2.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("请输入交易名称(必填)", row2.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(4), font, cellStyleMap.get("pop"));
|
||||
setCellValue("请输入服务名称(如果不填,则以交易名称为主)", row2.createCell(5), font, null);
|
||||
setCellValue("请输入服务场景(选填)", row2.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row2.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
|
||||
|
||||
XSSFRow row3 = sheet.createRow(2);
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(0), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(1), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(2), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(3), font, cellStyleMap.get("yellow"));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(4), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("请输入系统名称", row3.createCell(5), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(6), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(7), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(8), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row3.createCell(9), font, cellStyleMap.get("yellow"));
|
||||
CellRangeAddress region1 = new CellRangeAddress(2, 2, 0, 3);
|
||||
sheet.addMergedRegion(region1);
|
||||
CellRangeAddress region2 = new CellRangeAddress(2, 2, 5, 9);
|
||||
sheet.addMergedRegion(region2);
|
||||
|
||||
XSSFRow row4 = sheet.createRow(3);
|
||||
setCellValue("英文名称", row4.createCell(0), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("中文名称", row4.createCell(1), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("数据类型/长度", row4.createCell(2), font, cellStyleMap.get("yellow"));
|
||||
// if (isHead) {
|
||||
setCellValue("备注", row4.createCell(3), font, cellStyleMap.get("yellow"));
|
||||
setCellValue(StringUtils.EMPTY, row4.createCell(4), font, cellStyleMap.get("pop"));
|
||||
setCellValue("英文名称", row4.createCell(5), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("数据类型/长度", row4.createCell(6), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("中文名称", row4.createCell(7), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("备注", row4.createCell(8), font, cellStyleMap.get("yellow"));
|
||||
setCellValue("所在报文位置", row4.createCell(9), font, cellStyleMap.get("yellow"));
|
||||
|
||||
XSSFRow row5 = sheet.createRow(4);
|
||||
setCellValue("输入", row5.createCell(0), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(1), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(2), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(3), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(4), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(5), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(6), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(7), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(8), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row5.createCell(9), font, cellStyleMap.get("green"));
|
||||
|
||||
XSSFRow row6 = sheet.createRow(5);
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("请输入STRING(具体长度) 或 ARRAY", row6.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(4), font, cellStyleMap.get("pop"));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("请输入STRING(具体长度) 或 ARRAY", row6.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row6.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
|
||||
|
||||
XSSFRow row7 = sheet.createRow(6);
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(4), font, cellStyleMap.get("pop"));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row7.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
|
||||
|
||||
XSSFRow row8 = sheet.createRow(7);
|
||||
setCellValue("输出", row8.createCell(0), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(1), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(2), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(3), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(4), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(5), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(6), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(7), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(8), font, cellStyleMap.get("green"));
|
||||
setCellValue(StringUtils.EMPTY, row8.createCell(9), font, cellStyleMap.get("green"));
|
||||
|
||||
|
||||
XSSFRow row9 = sheet.createRow(8);
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(0), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(1), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("请输入STRING(具体长度) 或 ARRAY", row9.createCell(2), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(3), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
// if (isHead) {
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(4), font, cellStyleMap.get("pop"));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(5), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue("请输入STRING(具体长度) 或 ARRAY", row9.createCell(6), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(7), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(8), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
setCellValue(StringUtils.EMPTY, row9.createCell(9), font, cellStyleMap.get(PropertyConstant.DEFAULT));
|
||||
|
||||
}
|
||||
|
||||
private static void setCellValue(String textValue, Cell cell, XSSFFont font, XSSFCellStyle cellStyle) {
|
||||
XSSFRichTextString richString = new XSSFRichTextString(textValue);
|
||||
richString.applyFont(font);
|
||||
if (cellStyle != null) {
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
cell.setCellValue(richString);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) throws Exception {
|
||||
EsbExcelDataStruct excelDataStruct = this.esbImport(source);
|
||||
this.projectId = request.getProjectId();
|
||||
ApiDefinitionImport definitionImport = this.parseApiDefinitionImport(excelDataStruct, request);
|
||||
return definitionImport;
|
||||
}
|
||||
|
||||
public EsbExcelDataStruct esbImport(InputStream source) throws IOException, InvalidFormatException {
|
||||
Workbook workbook = WorkbookFactory.create(source);
|
||||
int sheetCount = workbook.getNumberOfSheets();
|
||||
EsbSheetDataStruct headStruct = null;
|
||||
List<EsbSheetDataStruct> interfaceStruct = new ArrayList<>();
|
||||
if (sheetCount > 0) {
|
||||
Sheet headSheet = workbook.getSheetAt(0);
|
||||
headStruct = this.parseExcelSheet(headSheet, true);
|
||||
for (int index = 1; index < sheetCount; index++) {
|
||||
Sheet dataSheet = workbook.getSheetAt(index);
|
||||
EsbSheetDataStruct bodyStruct = this.parseExcelSheet(dataSheet, false);
|
||||
interfaceStruct.add(bodyStruct);
|
||||
}
|
||||
}
|
||||
|
||||
EsbExcelDataStruct excelData = new EsbExcelDataStruct();
|
||||
excelData.setHeadData(headStruct);
|
||||
excelData.setInterfaceList(interfaceStruct);
|
||||
return excelData;
|
||||
}
|
||||
|
||||
private EsbSheetDataStruct parseExcelSheet(Sheet headSheet, boolean isHeadSheet) {
|
||||
EsbSheetDataStruct importDataStruct = new EsbSheetDataStruct();
|
||||
if (headSheet == null) {
|
||||
return importDataStruct;
|
||||
}
|
||||
ESBExcelSheetInfo sheetInfo = this.getEsbExcelSheetInfo(headSheet);
|
||||
|
||||
int rowCount = headSheet.getLastRowNum();
|
||||
|
||||
//根据模版样式,如果不是报文头,则要取接口信息
|
||||
if (!isHeadSheet) {
|
||||
Row interfaceInfoRow = headSheet.getRow(1);
|
||||
if (interfaceInfoRow != null) {
|
||||
List<String> rowDataArr = this.getRowDataByStartIndexAndEndIndex(interfaceInfoRow, 0, sheetInfo.getCellCount() - 1);
|
||||
if (rowDataArr.size() >= sheetInfo.getCellCount()) {
|
||||
String interfaceCode = rowDataArr.get(sheetInfo.getSimpleCodeIndex());
|
||||
String interfaceName = rowDataArr.get(sheetInfo.getServiceNameIndex());
|
||||
String interfaceDesc = rowDataArr.get(sheetInfo.getServiceScenarioIndex());
|
||||
if (StringUtils.isEmpty(interfaceName)) {
|
||||
interfaceName = rowDataArr.get(sheetInfo.getSimpleNameIndex());
|
||||
}
|
||||
importDataStruct.setInterfaceInfo(interfaceCode, interfaceName, interfaceDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
//超过10行为空白,直接退出。
|
||||
//部分office/wpf生成的文件会出现几万多空行,容易造成内存溢出。这里进行判断,连续五行为空白时认为读取结束。
|
||||
int blankRowCount = 0;
|
||||
boolean isRequest = true;
|
||||
|
||||
for (int startRow = sheetInfo.getRequestMessageRow(); startRow < rowCount; startRow++) {
|
||||
Row row = headSheet.getRow(startRow);
|
||||
List<String> rowDataArr = this.getRowDataByStartIndexAndEndIndex(row, 0, sheetInfo.getCellCount() - 1);
|
||||
boolean isBlankRow = this.checkBlankRow(rowDataArr, sheetInfo.getCellCount());
|
||||
if (!isBlankRow) {
|
||||
String cellFlag = rowDataArr.get(0);
|
||||
if (StringUtils.equals(cellFlag, "输出")) {
|
||||
isRequest = false;
|
||||
}
|
||||
}
|
||||
if (isBlankRow) {
|
||||
if (isRequest) {
|
||||
isRequest = false;
|
||||
}
|
||||
blankRowCount++;
|
||||
if (blankRowCount > 10) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
blankRowCount = 0;
|
||||
EsbDataStruct dataStruct = new EsbDataStruct();
|
||||
boolean initDataSuccess = dataStruct.initDefaultData(
|
||||
rowDataArr.get(sheetInfo.getApiNameIndex()), rowDataArr.get(sheetInfo.getDataTypeIndex()), rowDataArr.get(sheetInfo.getChineNameIndex()), rowDataArr.get(sheetInfo.getDescIndex()));
|
||||
if (!initDataSuccess) {
|
||||
continue;
|
||||
}
|
||||
boolean isHead = isHeadSheet;
|
||||
if (rowDataArr.size() > sheetInfo.getCellCount()) {
|
||||
if (StringUtils.equals(rowDataArr.get(sheetInfo.getApiPositionIndex()), "SYS_HEAD")) {
|
||||
isHead = true;
|
||||
}
|
||||
|
||||
}
|
||||
if (isRequest) {
|
||||
if (isHead) {
|
||||
importDataStruct.getReqHeadList().add(dataStruct);
|
||||
} else {
|
||||
importDataStruct.getRequestList().add(dataStruct);
|
||||
}
|
||||
} else {
|
||||
if (isHead) {
|
||||
importDataStruct.getRspHeadList().add(dataStruct);
|
||||
} else {
|
||||
importDataStruct.getResponseList().add(dataStruct);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return importDataStruct;
|
||||
}
|
||||
|
||||
private boolean checkBlankRow(List<String> rowDataArr, int rowCheckLength) {
|
||||
if (rowDataArr == null || rowDataArr.size() < rowCheckLength) {
|
||||
return true;
|
||||
}
|
||||
for (String str : rowDataArr) {
|
||||
if (StringUtils.isNotEmpty(str)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<String> getRowDataByStartIndexAndEndIndex(Row row, int startCell, int endCell) {
|
||||
List<String> returnArray = new ArrayList<>();
|
||||
if (row == null) {
|
||||
return returnArray;
|
||||
}
|
||||
for (int i = startCell; i <= endCell; i++) {
|
||||
Cell cell = row.getCell(i);
|
||||
if (cell != null) {
|
||||
returnArray.add(getCellValue(cell));
|
||||
} else {
|
||||
returnArray.add(StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
private String getCellValue(Cell cell) {
|
||||
String returnCellValue = StringUtils.EMPTY;
|
||||
if (cell.getCellType() == CellType.BLANK) {
|
||||
returnCellValue = StringUtils.EMPTY;
|
||||
} else if (cell.getCellType() == CellType.BOOLEAN) {
|
||||
returnCellValue = String.valueOf(cell.getBooleanCellValue());
|
||||
} else if (cell.getCellType() == CellType.ERROR) {
|
||||
returnCellValue = StringUtils.EMPTY;
|
||||
} else if (cell.getCellType() == CellType.NUMERIC) {
|
||||
returnCellValue = getValueOfNumericCell(cell);
|
||||
} else if (cell.getCellType() == CellType.FORMULA) {
|
||||
try {
|
||||
returnCellValue = getValueOfNumericCell(cell);
|
||||
} catch (IllegalStateException e) {
|
||||
try {
|
||||
returnCellValue = cell.getRichStringCellValue().toString();
|
||||
} catch (IllegalStateException e2) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
} else {
|
||||
returnCellValue = cell.getRichStringCellValue().getString();
|
||||
}
|
||||
if (returnCellValue == null) {
|
||||
returnCellValue = StringUtils.EMPTY;
|
||||
}
|
||||
return returnCellValue;
|
||||
}
|
||||
|
||||
private String getValueOfNumericCell(Cell cell) {
|
||||
Boolean isDate = DateUtil.isCellDateFormatted(cell);
|
||||
Double d = cell.getNumericCellValue();
|
||||
String o = null;
|
||||
if (isDate) {
|
||||
o = DateFormat.getDateTimeInstance()
|
||||
.format(cell.getDateCellValue());
|
||||
} else {
|
||||
o = getRealStringValueOfDouble(d);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
// 处理科学计数法与普通计数法的字符串显示,尽最大努力保持精度
|
||||
private static String getRealStringValueOfDouble(Double d) {
|
||||
String doubleStr = d.toString();
|
||||
boolean b = doubleStr.contains("E");
|
||||
int indexOfPoint = doubleStr.indexOf('.');
|
||||
if (b) {
|
||||
int indexOfE = doubleStr.indexOf('E');
|
||||
// 小数部分
|
||||
BigInteger xs = new BigInteger(doubleStr.substring(indexOfPoint
|
||||
+ BigInteger.ONE.intValue(), indexOfE));
|
||||
// 指数
|
||||
int pow = Integer.valueOf(doubleStr.substring(indexOfE
|
||||
+ BigInteger.ONE.intValue()));
|
||||
int xsLen = xs.toByteArray().length;
|
||||
int scale = xsLen - pow > 0 ? xsLen - pow : 0;
|
||||
doubleStr = String.format("%." + scale + "f", d);
|
||||
} else {
|
||||
Pattern p = Pattern.compile(".0$");
|
||||
java.util.regex.Matcher m = p.matcher(doubleStr);
|
||||
if (m.find()) {
|
||||
doubleStr = doubleStr.replace(".0", StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
return doubleStr;
|
||||
}
|
||||
|
||||
private ApiDefinitionImport parseApiDefinitionImport(EsbExcelDataStruct esbExcelDataStruct, ApiTestImportRequest importRequest) {
|
||||
ApiDefinitionImport resultModel = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> apiDataList = new ArrayList<>();
|
||||
|
||||
/*
|
||||
ApiModule parentNode = ApiDefinitionImportUtil.getSelectModule(importRequest.getModuleId());
|
||||
*/
|
||||
EsbSheetDataStruct headSheetData = esbExcelDataStruct.getHeadData();
|
||||
List<EsbSheetDataStruct> interfaceDataList = esbExcelDataStruct.getInterfaceList();
|
||||
List<String> savedNames = new ArrayList<>();
|
||||
Map<String, EsbApiParamsWithBLOBs> esbApiParams = new HashMap<>();
|
||||
for (EsbSheetDataStruct interfaceData : interfaceDataList) {
|
||||
String reqName = interfaceData.getServiceName();
|
||||
if (savedNames.contains(reqName)) {
|
||||
continue;
|
||||
} else {
|
||||
savedNames.add(reqName);
|
||||
}
|
||||
|
||||
String esbSendRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n${SERVICE}";
|
||||
String reqDataStructStr = generateDataStrcut(headSheetData, interfaceData, true);
|
||||
String respDataStrutStr = generateDataStrcut(headSheetData, interfaceData, false);
|
||||
|
||||
String apiId = UUID.randomUUID().toString();
|
||||
ApiDefinitionWithBLOBs apiDefinition = new ApiDefinitionWithBLOBs();
|
||||
apiDefinition.setName(reqName);
|
||||
apiDefinition.setMethod("ESB");
|
||||
apiDefinition.setId(apiId);
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
/* apiDefinition.setModuleId(importRequest.getModuleId());
|
||||
apiDefinition.setModulePath(importRequest.getModulePath());*/
|
||||
apiDefinition.setRequest(genTCPSampler(esbSendRequest, reqDataStructStr));
|
||||
if (StringUtils.equalsIgnoreCase("schedule", importRequest.getType())) {
|
||||
apiDefinition.setUserId(importRequest.getUserId());
|
||||
} else {
|
||||
apiDefinition.setUserId(SessionUtils.getUserId());
|
||||
}
|
||||
apiDefinition.setProtocol(RequestTypeConstants.TCP);
|
||||
/* buildModule(parentNode, apiDefinition, null);*/
|
||||
apiDataList.add(apiDefinition);
|
||||
|
||||
EsbApiParamsWithBLOBs apiParams = new EsbApiParamsWithBLOBs();
|
||||
apiParams.setId(UUID.randomUUID().toString());
|
||||
apiParams.setResourceId(apiId);
|
||||
|
||||
apiParams.setDataStruct(reqDataStructStr);
|
||||
apiParams.setResponseDataStruct(respDataStrutStr);
|
||||
esbApiParams.put(apiId, apiParams);
|
||||
}
|
||||
|
||||
resultModel.setData(apiDataList);
|
||||
resultModel.setEsbApiParamsMap(esbApiParams);
|
||||
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
private String genTCPSampler(String sendRequest, String esbDataStruct) {
|
||||
|
||||
MsTCPSampler tcpSampler = new MsTCPSampler();
|
||||
MsJSR223PreProcessor preProcessor = new MsJSR223PreProcessor();
|
||||
|
||||
tcpSampler.setTcpPreProcessor(preProcessor);
|
||||
tcpSampler.setProtocol("ESB");
|
||||
tcpSampler.setClassname("TCPClientImpl");
|
||||
tcpSampler.setReUseConnection(false);
|
||||
String script = "String report = ctx.getCurrentSampler().getRequestData();\n" +
|
||||
" if(report!=null){\n" +
|
||||
" //补足8位长度,前置补0\n" +
|
||||
" String reportlengthStr = String.format(\"%08d\",report.length());\n" +
|
||||
" report = reportlengthStr+report;\n" +
|
||||
" ctx.getCurrentSampler().setRequestData(report);\n" +
|
||||
" }";
|
||||
// frontScriptList.add(script);
|
||||
if (tcpSampler.getTcpPreProcessor() != null) {
|
||||
tcpSampler.getTcpPreProcessor().setScriptLanguage("groovy");
|
||||
tcpSampler.getTcpPreProcessor().setScript(script);
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.isNotEmpty(sendRequest)) {
|
||||
tcpSampler.setRequest(sendRequest);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(esbDataStruct)) {
|
||||
EsbApiParamService esbApiParamService = CommonBeanFactory.getBean(EsbApiParamService.class);
|
||||
List<KeyValue> keyValueList = esbApiParamService.genKeyValueListByDataStruct(tcpSampler, esbDataStruct);
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
|
||||
return JSON.toJSONString(tcpSampler);
|
||||
}
|
||||
|
||||
private String generateDataStrcut(EsbSheetDataStruct head, EsbSheetDataStruct body, boolean isRequest) {
|
||||
EsbDataStruct dataStruct = new EsbDataStruct();
|
||||
dataStruct.initDefaultData("SERVICE", null, null, null);
|
||||
List<EsbDataStruct> headList = new ArrayList<>();
|
||||
List<EsbDataStruct> bodyList = new ArrayList<>();
|
||||
if (head != null) {
|
||||
if (isRequest) {
|
||||
headList.addAll(head.getReqHeadList());
|
||||
bodyList.addAll(head.getRequestList());
|
||||
} else {
|
||||
headList.addAll(head.getRspHeadList());
|
||||
bodyList.addAll(head.getResponseList());
|
||||
}
|
||||
}
|
||||
if (body != null) {
|
||||
if (isRequest) {
|
||||
headList.addAll(body.getReqHeadList());
|
||||
bodyList.addAll(body.getRequestList());
|
||||
} else {
|
||||
headList.addAll(body.getRspHeadList());
|
||||
bodyList.addAll(body.getResponseList());
|
||||
}
|
||||
}
|
||||
|
||||
if (!headList.isEmpty()) {
|
||||
EsbDataStruct headStruct = new EsbDataStruct();
|
||||
headStruct.initDefaultData("SYS_HEAD", null, null, null);
|
||||
dataStruct.getChildren().add(headStruct);
|
||||
Map<String, EsbDataStruct> childrenEsbDataStructMap = new HashMap<>();
|
||||
//用来判断节点有没有在array节点内
|
||||
String lastArrayDataStrcutName = null;
|
||||
for (EsbDataStruct headData : headList) {
|
||||
if (StringUtils.equalsIgnoreCase(PropertyConstant.ARRAY, headData.getType())) {
|
||||
if (lastArrayDataStrcutName == null) {
|
||||
lastArrayDataStrcutName = headData.getName();
|
||||
EsbDataStruct arrayStrcut = new EsbDataStruct();
|
||||
arrayStrcut.initDefaultData(headData.getName(), headData.getType(), headData.getContentType(), headData.getDescription());
|
||||
headStruct.getChildren().add(arrayStrcut);
|
||||
childrenEsbDataStructMap.put(lastArrayDataStrcutName, arrayStrcut);
|
||||
} else {
|
||||
lastArrayDataStrcutName = null;
|
||||
}
|
||||
} else {
|
||||
if (lastArrayDataStrcutName == null) {
|
||||
headStruct.getChildren().add(headData);
|
||||
} else {
|
||||
EsbDataStruct arrayStrcut = childrenEsbDataStructMap.get(lastArrayDataStrcutName);
|
||||
if (arrayStrcut != null) {
|
||||
arrayStrcut.getChildren().add(headData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bodyList.isEmpty()) {
|
||||
EsbDataStruct bodyStruct = new EsbDataStruct();
|
||||
bodyStruct.initDefaultData("BODY", null, null, null);
|
||||
dataStruct.getChildren().add(bodyStruct);
|
||||
Map<String, EsbDataStruct> childrenEsbDataStructMap = new HashMap<>();
|
||||
//用来判断节点有没有在array节点内
|
||||
String lastArrayDataStrcutName = null;
|
||||
for (EsbDataStruct bodyData : bodyList) {
|
||||
if (StringUtils.equalsIgnoreCase(PropertyConstant.ARRAY, bodyData.getType())) {
|
||||
if (lastArrayDataStrcutName == null) {
|
||||
lastArrayDataStrcutName = bodyData.getName();
|
||||
EsbDataStruct arrayStrcut = new EsbDataStruct();
|
||||
arrayStrcut.initDefaultData(bodyData.getName(), bodyData.getType(), bodyData.getContentType(), bodyData.getDescription());
|
||||
bodyStruct.getChildren().add(arrayStrcut);
|
||||
childrenEsbDataStructMap.put(lastArrayDataStrcutName, arrayStrcut);
|
||||
} else {
|
||||
lastArrayDataStrcutName = null;
|
||||
}
|
||||
} else {
|
||||
if (lastArrayDataStrcutName == null) {
|
||||
bodyStruct.getChildren().add(bodyData);
|
||||
} else {
|
||||
EsbDataStruct arrayStrcut = childrenEsbDataStructMap.get(lastArrayDataStrcutName);
|
||||
if (arrayStrcut != null) {
|
||||
arrayStrcut.getChildren().add(bodyData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<EsbDataStruct> list = new ArrayList<>();
|
||||
list.add(dataStruct);
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
|
||||
private String getDefaultStringValue(String val) {
|
||||
return StringUtils.isBlank(val) ? StringUtils.EMPTY : val;
|
||||
}
|
||||
|
||||
private ESBExcelSheetInfo getEsbExcelSheetInfo(Sheet sheet) {
|
||||
String apiCodeCellName = "交易码";
|
||||
String apiNameCellName = "交易名称";
|
||||
String serviceNameCellName = "服务名称";
|
||||
String serviceScenarioCellName = "服务场景";
|
||||
|
||||
String englishCellName = "英文名称";
|
||||
String chineseCellName = "中文名称";
|
||||
String dataTypeCellName = "数据类型";
|
||||
String descCellName = "备注";
|
||||
|
||||
int maxContinuityEmptyCellCount = 10;
|
||||
|
||||
ESBExcelSheetInfo sheetInfo = new ESBExcelSheetInfo();
|
||||
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
rowForeach:
|
||||
for (int rowIndex = 0; rowIndex <= lastRowNum; rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row != null) {
|
||||
if (rowIndex == 0) {
|
||||
int lastCellNumber = row.getLastCellNum();
|
||||
|
||||
//连续空白数据的统计:超过连续maxContinuityEmptyCellCount个空白数据时,停止读取当前行。
|
||||
// (某些Excel进行读取时会有缺陷:单元格没有数据,但是因为格式进行过设置,会一直读取,容易造成内存溢出)
|
||||
int continuityEmptyCount = 0;
|
||||
|
||||
cellForeach:
|
||||
for (int i = 0; i <= lastCellNumber; i++) {
|
||||
Cell cell = row.getCell(i);
|
||||
if (cell != null) {
|
||||
String cellValue = this.getCellValue(cell).trim();
|
||||
if (StringUtils.isEmpty(cellValue)) {
|
||||
continuityEmptyCount++;
|
||||
if (continuityEmptyCount > maxContinuityEmptyCellCount) {
|
||||
break cellForeach;
|
||||
}
|
||||
} else {
|
||||
continuityEmptyCount = 0;
|
||||
if (StringUtils.equals(cellValue, apiCodeCellName)) {
|
||||
sheetInfo.setSimpleCodeIndex(i);
|
||||
} else if (StringUtils.equals(cellValue, apiNameCellName)) {
|
||||
sheetInfo.setSimpleNameIndex(i);
|
||||
} else if (StringUtils.equals(cellValue, serviceNameCellName)) {
|
||||
sheetInfo.setServiceNameIndex(i);
|
||||
} else if (StringUtils.equals(cellValue, serviceScenarioCellName)) {
|
||||
sheetInfo.setServiceScenarioIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//根据第一行《服务名称》的起始列下标开始读取, 进行匹配(英文名称、数据类型/长度、中文名称、备注)
|
||||
int startReadIndex = sheetInfo.getApiNameIndex();
|
||||
int lastCellNumber = row.getLastCellNum();
|
||||
|
||||
int continuityEmptyCount = 0;
|
||||
cellForeach:
|
||||
for (int i = startReadIndex; i < lastCellNumber; i++) {
|
||||
Cell cell = row.getCell(i);
|
||||
if (cell != null) {
|
||||
String cellValue = this.getCellValue(cell).trim();
|
||||
if (StringUtils.isEmpty(cellValue)) {
|
||||
continuityEmptyCount++;
|
||||
if (continuityEmptyCount > maxContinuityEmptyCellCount) {
|
||||
break cellForeach;
|
||||
}
|
||||
} else {
|
||||
continuityEmptyCount = 0;
|
||||
if (StringUtils.equals(cellValue, englishCellName)) {
|
||||
sheetInfo.setApiNameIndex(i);
|
||||
} else if (StringUtils.equals(cellValue, chineseCellName)) {
|
||||
sheetInfo.setChineNameIndex(i);
|
||||
} else if (StringUtils.contains(cellValue, dataTypeCellName)) {
|
||||
sheetInfo.setDataTypeIndex(i);
|
||||
} else if (StringUtils.equals(cellValue, descCellName)) {
|
||||
sheetInfo.setDescIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sheetInfo.installedApiInfoIndex()) {
|
||||
sheetInfo.countApiPosisionIndex();
|
||||
sheetInfo.setRequestMessageRow(rowIndex + 1);
|
||||
break rowForeach;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sheetInfo;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package io.metersphere.api.parse.api;
|
||||
|
||||
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/10 11:15 上午
|
||||
* @Description
|
||||
*/
|
||||
public abstract class EsbAbstractParser extends ApiImportAbstractParser<ApiDefinitionImport> {
|
||||
|
||||
protected void buildModule(ApiModule parentModule, ApiDefinitionWithBLOBs apiDefinition, List<String> tags) {
|
||||
if (tags != null) {
|
||||
tags.forEach(tag -> {
|
||||
ApiModule module = ApiDefinitionImportUtil.buildModule(parentModule, tag, this.projectId);
|
||||
apiDefinition.setModuleId(module.getId());
|
||||
});
|
||||
} else {
|
||||
apiDefinition.setModuleId(parentModule.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package io.metersphere.api.parse.api.esb;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/5/6 3:25 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ESBExcelSheetInfo {
|
||||
//交易码下标
|
||||
private int simpleCodeIndex = 0;
|
||||
//交易名称下标
|
||||
private int simpleNameIndex = 0;
|
||||
//服务名下标
|
||||
private int serviceNameIndex = 0;
|
||||
//服务场景下标
|
||||
private int serviceScenarioIndex = 0;
|
||||
|
||||
//接口名字下标
|
||||
private int apiNameIndex = 0;
|
||||
//数据类型下标
|
||||
private int dataTypeIndex = 0;
|
||||
//中文名称
|
||||
private int chineNameIndex = 0;
|
||||
//描述
|
||||
private int descIndex = 0;
|
||||
//api位置
|
||||
private int apiPositionIndex = 0;
|
||||
//每一行的单元格最大长度
|
||||
private int cellCount = 0;
|
||||
//请求信息起始行
|
||||
private int requestMessageRow = 0;
|
||||
//允许的最大空白行数(连续超过这个数字的空白行则认为sheet读取结束)
|
||||
private int maxEmptyRowCount = 20;
|
||||
|
||||
public boolean installedApiInfoIndex() {
|
||||
return (apiNameIndex != 0 && dataTypeIndex != 0);
|
||||
}
|
||||
|
||||
public void countApiPosisionIndex() {
|
||||
apiPositionIndex = apiNameIndex > apiPositionIndex ? apiNameIndex : apiPositionIndex;
|
||||
apiPositionIndex = dataTypeIndex > apiPositionIndex ? dataTypeIndex : apiPositionIndex;
|
||||
apiPositionIndex = chineNameIndex > apiPositionIndex ? chineNameIndex : apiPositionIndex;
|
||||
apiPositionIndex = descIndex > apiPositionIndex ? descIndex : apiPositionIndex;
|
||||
apiPositionIndex++;
|
||||
cellCount = apiPositionIndex;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package io.metersphere.api.parse.api.esb;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/23 12:55 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class EsbExcelDataStruct {
|
||||
private EsbSheetDataStruct headData;
|
||||
private List<EsbSheetDataStruct> interfaceList = new ArrayList<>();
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package io.metersphere.api.parse.api.esb;
|
||||
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/22 9:42 下午
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class EsbSheetDataStruct {
|
||||
private String serviceName;
|
||||
private String serviceDesc;
|
||||
private List<EsbDataStruct> requestList = new ArrayList<>();
|
||||
private List<EsbDataStruct> responseList = new ArrayList<>();
|
||||
|
||||
//单个接口内也可能有报文头中要增加的数据
|
||||
private List<EsbDataStruct> reqHeadList = new ArrayList<>();
|
||||
private List<EsbDataStruct> rspHeadList = new ArrayList<>();
|
||||
|
||||
|
||||
public void setInterfaceInfo(String interfaceCode, String interfaceName, String interfaceDesc) {
|
||||
if (StringUtils.isEmpty(interfaceCode) && StringUtils.isEmpty(interfaceName)) {
|
||||
MSException.throwException("接口的交易码或服务名称不能都为空");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(interfaceCode)) {
|
||||
this.serviceName = interfaceCode + ":" + interfaceName;
|
||||
} else {
|
||||
this.serviceName = interfaceName;
|
||||
}
|
||||
if (this.serviceName.endsWith(":")) {
|
||||
this.serviceName = this.serviceName.substring(0, this.serviceName.length() - 1);
|
||||
}
|
||||
this.serviceDesc = interfaceDesc;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package io.metersphere.api.parse.scenario;
|
||||
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/15 5:00 下午
|
||||
* @Description
|
||||
*/
|
||||
public class EsbDataParser {
|
||||
public static String esbData2XmlByParamStruct(List<EsbDataStruct> esbDataList, String[] paramArr) {
|
||||
String xmlString = StringUtils.EMPTY;
|
||||
try {
|
||||
if (esbDataList == null || esbDataList.isEmpty()) {
|
||||
return xmlString;
|
||||
}
|
||||
Document document = DocumentHelper.createDocument();
|
||||
EsbDataStruct dataStruct = selectEsbDataStructByNameStruct(esbDataList, paramArr, 0);
|
||||
if (dataStruct != null) {
|
||||
dataStruct.genXmlElementByDocument(document);
|
||||
xmlString = document.getRootElement().asXML();
|
||||
|
||||
// 设置XML文档格式
|
||||
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
|
||||
// 设置XML编码方式,即是用指定的编码方式保存XML文档到字符串(String),这里也可以指定为GBK或是ISO8859-1
|
||||
outputFormat.setEncoding(StandardCharsets.UTF_8.name());
|
||||
//outputFormat.setSuppressDeclaration(true); //是否生产xml头
|
||||
outputFormat.setIndent(true); //设置是否缩进
|
||||
outputFormat.setNewlines(true); //设置是否换行
|
||||
|
||||
try {
|
||||
// stringWriter字符串是用来保存XML文档的
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
// xmlWriter是用来把XML文档写入字符串的(工具)
|
||||
XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat);
|
||||
// 把创建好的XML文档写入字符串
|
||||
xmlWriter.write(document);
|
||||
|
||||
// 打印字符串,即是XML文档
|
||||
xmlString = stringWriter.toString();
|
||||
xmlWriter.close();
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
if (StringUtils.isEmpty(xmlString)) {
|
||||
xmlString = StringUtils.EMPTY;
|
||||
} else {
|
||||
xmlString = xmlString.replaceAll(" ", StringUtils.EMPTY);
|
||||
}
|
||||
return xmlString;
|
||||
}
|
||||
|
||||
//根据参数结构,递归查询数据
|
||||
private static EsbDataStruct selectEsbDataStructByNameStruct(List<EsbDataStruct> esbDataList, String[] paramArr, int index) {
|
||||
EsbDataStruct returnData = null;
|
||||
if (paramArr.length > index) {
|
||||
String param = paramArr[index];
|
||||
for (EsbDataStruct dataStruct : esbDataList) {
|
||||
if (StringUtils.equals(dataStruct.getName(), param)) {
|
||||
int newIndex = index + 1;
|
||||
if (paramArr.length > newIndex && dataStruct.getChildren() != null) {
|
||||
EsbDataStruct childElement = selectEsbDataStructByNameStruct(dataStruct.getChildren(), paramArr, newIndex);
|
||||
if (childElement != null) {
|
||||
returnData = dataStruct.copy(false);
|
||||
returnData.getChildren().add(childElement);
|
||||
}
|
||||
} else {
|
||||
returnData = dataStruct.copy(true);
|
||||
}
|
||||
} else if (index == 0) {
|
||||
//如果是第一个节点不符合,则遍历子节点是否有符合的。
|
||||
int newIndex = index;
|
||||
EsbDataStruct itemData = selectEsbDataStructByNameStruct(dataStruct.getChildren(), paramArr, newIndex);
|
||||
if (itemData != null) {
|
||||
returnData = itemData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.base.domain.EsbApiParams;
|
||||
import io.metersphere.base.domain.EsbApiParamsExample;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EsbApiParamsMapper {
|
||||
long countByExample(EsbApiParamsExample example);
|
||||
|
||||
int deleteByExample(EsbApiParamsExample example);
|
||||
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(EsbApiParamsWithBLOBs record);
|
||||
|
||||
int insertSelective(EsbApiParamsWithBLOBs record);
|
||||
|
||||
List<EsbApiParamsWithBLOBs> selectByExampleWithBLOBs(EsbApiParamsExample example);
|
||||
|
||||
List<EsbApiParams> selectByExample(EsbApiParamsExample example);
|
||||
|
||||
EsbApiParamsWithBLOBs selectByPrimaryKey(String id);
|
||||
|
||||
int updateByExampleSelective(@Param("record") EsbApiParamsWithBLOBs record, @Param("example") EsbApiParamsExample example);
|
||||
|
||||
int updateByExampleWithBLOBs(@Param("record") EsbApiParamsWithBLOBs record, @Param("example") EsbApiParamsExample example);
|
||||
|
||||
int updateByExample(@Param("record") EsbApiParams record, @Param("example") EsbApiParamsExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(EsbApiParamsWithBLOBs record);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(EsbApiParamsWithBLOBs record);
|
||||
|
||||
int updateByPrimaryKey(EsbApiParams record);
|
||||
}
|
|
@ -1,264 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.base.mapper.EsbApiParamsMapper">
|
||||
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.EsbApiParams">
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
|
||||
</resultMap>
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.EsbApiParamsWithBLOBs">
|
||||
<result column="data_struct" jdbcType="LONGVARCHAR" property="dataStruct" />
|
||||
<result column="fronted_script" jdbcType="LONGVARCHAR" property="frontedScript" />
|
||||
<result column="response_data_struct" jdbcType="LONGVARCHAR" property="responseDataStruct" />
|
||||
<result column="backed_script" jdbcType="LONGVARCHAR" property="backedScript" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Update_By_Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="example.oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, resource_id
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
data_struct, fronted_script, response_data_struct, backed_script
|
||||
</sql>
|
||||
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.EsbApiParamsExample" resultMap="ResultMapWithBLOBs">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
,
|
||||
<include refid="Blob_Column_List" />
|
||||
from esb_api_params
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByExample" parameterType="io.metersphere.base.domain.EsbApiParamsExample" resultMap="BaseResultMap">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
from esb_api_params
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
,
|
||||
<include refid="Blob_Column_List" />
|
||||
from esb_api_params
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from esb_api_params
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.EsbApiParamsExample">
|
||||
delete from esb_api_params
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.EsbApiParamsWithBLOBs">
|
||||
insert into esb_api_params (id, resource_id, data_struct,
|
||||
fronted_script, response_data_struct,
|
||||
backed_script)
|
||||
values (#{id,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, #{dataStruct,jdbcType=LONGVARCHAR},
|
||||
#{frontedScript,jdbcType=LONGVARCHAR}, #{responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
#{backedScript,jdbcType=LONGVARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.EsbApiParamsWithBLOBs">
|
||||
insert into esb_api_params
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
id,
|
||||
</if>
|
||||
<if test="resourceId != null">
|
||||
resource_id,
|
||||
</if>
|
||||
<if test="dataStruct != null">
|
||||
data_struct,
|
||||
</if>
|
||||
<if test="frontedScript != null">
|
||||
fronted_script,
|
||||
</if>
|
||||
<if test="responseDataStruct != null">
|
||||
response_data_struct,
|
||||
</if>
|
||||
<if test="backedScript != null">
|
||||
backed_script,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
#{id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="resourceId != null">
|
||||
#{resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="dataStruct != null">
|
||||
#{dataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="frontedScript != null">
|
||||
#{frontedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="responseDataStruct != null">
|
||||
#{responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="backedScript != null">
|
||||
#{backedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.EsbApiParamsExample" resultType="java.lang.Long">
|
||||
select count(*) from esb_api_params
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</select>
|
||||
<update id="updateByExampleSelective" parameterType="map">
|
||||
update esb_api_params
|
||||
<set>
|
||||
<if test="record.id != null">
|
||||
id = #{record.id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.resourceId != null">
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.dataStruct != null">
|
||||
data_struct = #{record.dataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.frontedScript != null">
|
||||
fronted_script = #{record.frontedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.responseDataStruct != null">
|
||||
response_data_struct = #{record.responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.backedScript != null">
|
||||
backed_script = #{record.backedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExampleWithBLOBs" parameterType="map">
|
||||
update esb_api_params
|
||||
set id = #{record.id,jdbcType=VARCHAR},
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR},
|
||||
data_struct = #{record.dataStruct,jdbcType=LONGVARCHAR},
|
||||
fronted_script = #{record.frontedScript,jdbcType=LONGVARCHAR},
|
||||
response_data_struct = #{record.responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
backed_script = #{record.backedScript,jdbcType=LONGVARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update esb_api_params
|
||||
set id = #{record.id,jdbcType=VARCHAR},
|
||||
resource_id = #{record.resourceId,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.EsbApiParamsWithBLOBs">
|
||||
update esb_api_params
|
||||
<set>
|
||||
<if test="resourceId != null">
|
||||
resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="dataStruct != null">
|
||||
data_struct = #{dataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="frontedScript != null">
|
||||
fronted_script = #{frontedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="responseDataStruct != null">
|
||||
response_data_struct = #{responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="backedScript != null">
|
||||
backed_script = #{backedScript,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.EsbApiParamsWithBLOBs">
|
||||
update esb_api_params
|
||||
set resource_id = #{resourceId,jdbcType=VARCHAR},
|
||||
data_struct = #{dataStruct,jdbcType=LONGVARCHAR},
|
||||
fronted_script = #{frontedScript,jdbcType=LONGVARCHAR},
|
||||
response_data_struct = #{responseDataStruct,jdbcType=LONGVARCHAR},
|
||||
backed_script = #{backedScript,jdbcType=LONGVARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.EsbApiParams">
|
||||
update esb_api_params
|
||||
set resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -26,8 +26,6 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
|||
public static final String JSON_END = "}";
|
||||
public static final String TYPE = "type";
|
||||
public static final String HTTP = "HTTP";
|
||||
public static final String ESB = "ESB";
|
||||
public static final String BACK_ESB = "backEsbDataStruct";
|
||||
public static final String BACK_SCRIPT = "backScript";
|
||||
public static final String HEADS = "headers";
|
||||
public static final String STATUS_CODE = "statusCode";
|
||||
|
@ -54,36 +52,9 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
|||
diffMap.put(TYPE, bloBsIsNew.getString(TYPE));
|
||||
}
|
||||
}
|
||||
if (bloBsIsNew.getString(TYPE).equals(ESB)) {
|
||||
diffEsbResponse(bloBsIsNew, bloBsIsOld, diffMap);
|
||||
if (diffMap.size() > 0) {
|
||||
diffMap.put(TYPE, bloBsIsNew.getString(TYPE));
|
||||
}
|
||||
}
|
||||
return JSON.toJSONString(diffMap);
|
||||
}
|
||||
|
||||
private static void diffEsbResponse(JSONObject bloBsIsNew, JSONObject bloBsIsOld, Map<String, String> diffMap) {
|
||||
//对比响应报文
|
||||
if (bloBsIsNew.get(BACK_ESB) != null && bloBsIsOld.get(BACK_ESB) != null) {
|
||||
String backEsbDataStructNew = StringUtils.join(StringUtils.join(JSON_START, bloBsIsNew.get(BACK_ESB).toString()), JSON_END);
|
||||
String backEsbDataStructOld = StringUtils.join(StringUtils.join(JSON_START, bloBsIsOld.get(BACK_ESB).toString()), JSON_END);
|
||||
if (!StringUtils.equals(backEsbDataStructNew, backEsbDataStructOld)) {
|
||||
diffMap.put(StringUtils.join(BACK_ESB, "1"), backEsbDataStructNew);
|
||||
diffMap.put(StringUtils.join(BACK_ESB, "2"), backEsbDataStructOld);
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(bloBsIsNew.getString(BACK_SCRIPT), bloBsIsOld.getString(BACK_SCRIPT))) {
|
||||
String backScriptNew = StringUtils.join(StringUtils.join(JSON_START, bloBsIsNew.get(BACK_SCRIPT).toString()), JSON_END);
|
||||
String backScriptOld = StringUtils.join(StringUtils.join(JSON_START, bloBsIsOld.get(BACK_SCRIPT).toString()), JSON_END);
|
||||
if (!StringUtils.equals(backScriptNew, backScriptOld)) {
|
||||
diffMap.put(StringUtils.join(BACK_SCRIPT, "1"), backScriptNew);
|
||||
diffMap.put(StringUtils.join(BACK_SCRIPT, "2"), backScriptOld);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String diff(String newValue, String oldValue) {
|
||||
try {
|
||||
|
@ -285,82 +256,50 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
|||
}
|
||||
|
||||
private static void diffTcp(MsTCPSampler tcpNew, MsTCPSampler tcpOld, JsonDiff jsonDiff, Map<String, String> diffMap) {
|
||||
if ((ESB).equals(tcpNew.getProtocol()) && (ESB).equals(tcpOld.getProtocol())) {
|
||||
diffMap.put(TYPE, ESB);
|
||||
//对比参数
|
||||
String queryNewEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getEsbDataStruct())), JSON_END);
|
||||
String queryOldEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getEsbDataStruct())), JSON_END);
|
||||
if (!StringUtils.equals(queryNewEsb, queryOldEsb)) {
|
||||
diffMap.put(StringUtils.join(QUERY, "1"), queryNewEsb);
|
||||
diffMap.put(StringUtils.join(QUERY, "2"), queryOldEsb);
|
||||
// 对比请求参数
|
||||
if (CollectionUtils.isNotEmpty(tcpNew.getParameters())) {
|
||||
tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1);
|
||||
tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1);
|
||||
}
|
||||
String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters())), JSON_END);
|
||||
String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters())), JSON_END);
|
||||
if (!StringUtils.equals(queryNew, queryOld)) {
|
||||
String patch = jsonDiff.diff(queryOld, queryNew);
|
||||
String diff = jsonDiff.apply(queryNew, patch);
|
||||
if (StringUtils.isNotEmpty(diff)) {
|
||||
diffMap.put(QUERY, diff);
|
||||
}
|
||||
//报文模版
|
||||
String requestNewEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getRequest())), JSON_END);
|
||||
String requestOldEsb = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getRequest())), JSON_END);
|
||||
if (!StringUtils.equals(requestNewEsb, requestOldEsb)) {
|
||||
diffMap.put(StringUtils.join(REQUEST, "1"), requestNewEsb);
|
||||
diffMap.put(StringUtils.join(REQUEST, "2"), requestOldEsb);
|
||||
}
|
||||
// 对比BODY-JSON参数
|
||||
if (!StringUtils.equals(tcpNew.getJsonDataStruct(), tcpOld.getJsonDataStruct())) {
|
||||
String patch = jsonDiff.diff(tcpOld.getJsonDataStruct(), tcpNew.getJsonDataStruct());
|
||||
String diff = jsonDiff.apply(tcpNew.getJsonDataStruct(), patch);
|
||||
if (StringUtils.isNotEmpty(diff) && !StringUtils.equals(patch, "{}")) {
|
||||
diffMap.put("body_json", diff);
|
||||
}
|
||||
// 其他设置
|
||||
List<DetailColumn> columns = ReflexObjectUtil.getColumns(tcpNew, DefinitionReference.esbColumns);
|
||||
List<DetailColumn> columnsOld = ReflexObjectUtil.getColumns(tcpOld, DefinitionReference.esbColumns);
|
||||
List<DetailColumn> diffColumns = getColumn(columns, columnsOld);
|
||||
if (CollectionUtils.isNotEmpty(diffColumns)) {
|
||||
diffMap.put("otherConfig", JSON.toJSONString(diffColumns));
|
||||
}
|
||||
} else {
|
||||
// 对比请求参数
|
||||
if (CollectionUtils.isNotEmpty(tcpNew.getParameters())) {
|
||||
tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1);
|
||||
tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1);
|
||||
}
|
||||
String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters())), JSON_END);
|
||||
String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters())), JSON_END);
|
||||
if (!StringUtils.equals(queryNew, queryOld)) {
|
||||
String patch = jsonDiff.diff(queryOld, queryNew);
|
||||
String diff = jsonDiff.apply(queryNew, patch);
|
||||
if (StringUtils.isNotEmpty(diff)) {
|
||||
diffMap.put(QUERY, diff);
|
||||
}
|
||||
}
|
||||
// 对比BODY-JSON参数
|
||||
if (!StringUtils.equals(tcpNew.getJsonDataStruct(), tcpOld.getJsonDataStruct())) {
|
||||
String patch = jsonDiff.diff(tcpOld.getJsonDataStruct(), tcpNew.getJsonDataStruct());
|
||||
String diff = jsonDiff.apply(tcpNew.getJsonDataStruct(), patch);
|
||||
if (StringUtils.isNotEmpty(diff) && !StringUtils.equals(patch, "{}")) {
|
||||
diffMap.put("body_json", diff);
|
||||
}
|
||||
}
|
||||
// 对比BODY-XML参数
|
||||
String xmlNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct())), JSON_END);
|
||||
String xmlOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct())), JSON_END);
|
||||
if (!StringUtils.equals(xmlNew, xmlOld)) {
|
||||
diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct()));
|
||||
diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct()));
|
||||
String patch = jsonDiff.diff(xmlOld, xmlNew);
|
||||
String diffPatch = jsonDiff.apply(xmlNew, patch);
|
||||
if (StringUtils.isNotEmpty(diffPatch)) {
|
||||
diffMap.put(BODY_XML, diffPatch);
|
||||
}
|
||||
}
|
||||
// 对比BODY-RAW参数
|
||||
if (!StringUtils.equals(tcpNew.getRawDataStruct(), tcpOld.getRawDataStruct())) {
|
||||
diffMap.put(StringUtils.join(BODY_RAW, "_1"), tcpNew.getRawDataStruct());
|
||||
diffMap.put(StringUtils.join(BODY_RAW, "_2"), tcpOld.getRawDataStruct());
|
||||
}
|
||||
// 对比pre参数
|
||||
if (tcpNew.getTcpPreProcessor() != null && !StringUtils.equals(tcpNew.getTcpPreProcessor().getScript(), tcpOld.getTcpPreProcessor().getScript())) {
|
||||
diffMap.put(StringUtils.join(SCRIPT, "_1"), tcpNew.getTcpPreProcessor().getScript());
|
||||
diffMap.put(StringUtils.join(SCRIPT, "_2"), tcpOld.getTcpPreProcessor().getScript());
|
||||
}
|
||||
// 其他设置
|
||||
List<DetailColumn> columns = ReflexObjectUtil.getColumns(tcpNew, DefinitionReference.esbColumns);
|
||||
List<DetailColumn> columnsOld = ReflexObjectUtil.getColumns(tcpOld, DefinitionReference.esbColumns);
|
||||
List<DetailColumn> diffColumns = getColumn(columns, columnsOld);
|
||||
if (CollectionUtils.isNotEmpty(diffColumns)) {
|
||||
diffMap.put("other_config", JSON.toJSONString(diffColumns));
|
||||
}
|
||||
// 对比BODY-XML参数
|
||||
String xmlNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct())), JSON_END);
|
||||
String xmlOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct())), JSON_END);
|
||||
if (!StringUtils.equals(xmlNew, xmlOld)) {
|
||||
diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct()));
|
||||
diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct()));
|
||||
String patch = jsonDiff.diff(xmlOld, xmlNew);
|
||||
String diffPatch = jsonDiff.apply(xmlNew, patch);
|
||||
if (StringUtils.isNotEmpty(diffPatch)) {
|
||||
diffMap.put(BODY_XML, diffPatch);
|
||||
}
|
||||
}
|
||||
// 对比BODY-RAW参数
|
||||
if (!StringUtils.equals(tcpNew.getRawDataStruct(), tcpOld.getRawDataStruct())) {
|
||||
diffMap.put(StringUtils.join(BODY_RAW, "_1"), tcpNew.getRawDataStruct());
|
||||
diffMap.put(StringUtils.join(BODY_RAW, "_2"), tcpOld.getRawDataStruct());
|
||||
}
|
||||
// 对比pre参数
|
||||
if (tcpNew.getTcpPreProcessor() != null && !StringUtils.equals(tcpNew.getTcpPreProcessor().getScript(), tcpOld.getTcpPreProcessor().getScript())) {
|
||||
diffMap.put(StringUtils.join(SCRIPT, "_1"), tcpNew.getTcpPreProcessor().getScript());
|
||||
diffMap.put(StringUtils.join(SCRIPT, "_2"), tcpOld.getTcpPreProcessor().getScript());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,15 +34,12 @@ import io.metersphere.log.annotation.MsAuditLog;
|
|||
import io.metersphere.notice.annotation.SendNotice;
|
||||
import io.metersphere.request.ResetOrderRequest;
|
||||
import io.metersphere.service.definition.ApiDefinitionService;
|
||||
import io.metersphere.service.definition.EsbApiParamService;
|
||||
import io.metersphere.service.definition.EsbImportService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -52,10 +49,6 @@ public class ApiDefinitionController {
|
|||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
@Resource
|
||||
private EsbImportService esbImportService;
|
||||
@Resource
|
||||
private BaseEnvironmentService apiTestEnvironmentService;
|
||||
@Resource
|
||||
private ExecThreadPoolExecutor execThreadPoolExecutor;
|
||||
|
@ -140,15 +133,6 @@ public class ApiDefinitionController {
|
|||
apiDefinitionService.deleteBatch(ids);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/updateEsbRequest")
|
||||
public SaveApiDefinitionRequest updateEsbRequest(@RequestBody SaveApiDefinitionRequest request) {
|
||||
if (StringUtils.equals(request.getMethod(), "ESB")) {
|
||||
//ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据
|
||||
request = esbApiParamService.updateEsbRequest(request);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
@PostMapping("/del-batch")
|
||||
@MsAuditLog(module = OperLogModule.API_DEFINITION, type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiDefinitionService.class)
|
||||
public void deleteBatchByParams(@RequestBody ApiBatchRequest request) {
|
||||
|
@ -310,12 +294,6 @@ public class ApiDefinitionController {
|
|||
return JSONSchemaGenerator.getJson(jsonSchema);
|
||||
}
|
||||
|
||||
@GetMapping("/export-esb-template")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_EXPORT_API)
|
||||
public void testCaseTemplateExport(HttpServletResponse response) {
|
||||
esbImportService.templateExport(response);
|
||||
}
|
||||
|
||||
@GetMapping("/mock-environment/{projectId}")
|
||||
public ApiTestEnvironmentWithBLOBs getMockEnvironment(@PathVariable String projectId) {
|
||||
return apiTestEnvironmentService.getMockEnvironmentByProjectId(projectId);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
|
||||
import io.metersphere.api.dto.mock.*;
|
||||
import io.metersphere.api.dto.mock.config.MockConfigImportDTO;
|
||||
|
@ -740,11 +739,6 @@ public class MockConfigService {
|
|||
paramNameList = this.parseByTcpTreeDataStruct(requestObj.optString("xmlDataStruct"));
|
||||
} else if (StringUtils.equalsIgnoreCase(reportType, "json") && requestObj.has("jsonDataStruct")) {
|
||||
paramNameList = this.parseByJsonDataStruct(requestObj.optString("jsonDataStruct"));
|
||||
} else if (requestObj.has("protocol")) {
|
||||
String protocol = requestObj.optString("protocol");
|
||||
if (StringUtils.equalsIgnoreCase("ESB", protocol) && requestObj.has("esbDataStruct")) {
|
||||
paramNameList = this.parseByESBDataStruct(requestObj.optString("esbDataStruct"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1005,20 +999,6 @@ public class MockConfigService {
|
|||
return returnList;
|
||||
}
|
||||
|
||||
private List<String> parseByESBDataStruct(String dataString) {
|
||||
List<EsbDataStruct> list = JSON.parseArray(dataString, EsbDataStruct.class);
|
||||
List<String> returnList = new ArrayList<>();
|
||||
for (EsbDataStruct dataStruct : list) {
|
||||
List<String> nameList = dataStruct.getNameDeep();
|
||||
for (String name : nameList) {
|
||||
if (!returnList.contains(nameList)) {
|
||||
returnList.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public MockExpectConfigDTO matchTcpMockExpect(String message, int port) {
|
||||
ProjectApplicationExample pae = new ProjectApplicationExample();
|
||||
pae.createCriteria().andTypeEqualTo(ProjectApplicationType.MOCK_TCP_PORT.name()).andTypeValueEqualTo(String.valueOf(port));
|
||||
|
|
|
@ -5,11 +5,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.parse.api.ApiDefinitionImport;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.EsbApiParamsMapper;
|
||||
import io.metersphere.commons.constants.NoticeConstants;
|
||||
import io.metersphere.commons.constants.PropertyConstant;
|
||||
import io.metersphere.commons.enums.ApiTestDataStatus;
|
||||
|
@ -24,7 +22,6 @@ import io.metersphere.xpack.api.service.ApiDefinitionSyncService;
|
|||
import org.apache.commons.beanutils.BeanMap;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -403,22 +400,4 @@ public class ApiDefinitionImportUtil {
|
|||
return oldCaseMap;
|
||||
}
|
||||
|
||||
public static void delEsbData(ApiDefinitionImport apiImport, SqlSession sqlSession) {
|
||||
if (apiImport.getEsbApiParamsMap() != null && apiImport.getEsbApiParamsMap().size() > 0) {
|
||||
EsbApiParamsMapper esbApiParamsMapper = sqlSession.getMapper(EsbApiParamsMapper.class);
|
||||
for (EsbApiParamsWithBLOBs model : apiImport.getEsbApiParamsMap().values()) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdEqualTo(model.getResourceId());
|
||||
List<EsbApiParamsWithBLOBs> exitModelList = esbApiParamsMapper.selectByExampleWithBLOBs(example);
|
||||
if (exitModelList.isEmpty()) {
|
||||
esbApiParamsMapper.insert(model);
|
||||
} else {
|
||||
model.setId(exitModelList.get(0).getId());
|
||||
esbApiParamsMapper.updateByPrimaryKeyWithBLOBs(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -207,17 +207,15 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
|
||||
} else {
|
||||
Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap = apiImport.getEsbApiParamsMap();
|
||||
|
||||
repeatList = dealRepeat(request, optionData, moduleMap, fullCoverage, idPathMap, chooseModule, esbApiParamsMap, toUpdateList, optionDataCases);
|
||||
repeatList = dealRepeat(request, optionData, moduleMap, fullCoverage, idPathMap, chooseModule, toUpdateList, optionDataCases);
|
||||
}
|
||||
|
||||
if (MapUtils.isNotEmpty(moduleMap)) {
|
||||
moduleMap.forEach((k,v)-> apiModuleMapper.insert(v));
|
||||
moduleMap.forEach((k, v) -> apiModuleMapper.insert(v));
|
||||
}
|
||||
int num = 0;
|
||||
if (!CollectionUtils.isEmpty(optionData) && optionData.get(0) != null && optionData.get(0).getProjectId() != null) {
|
||||
num = getNextNum(optionData.get(0).getProjectId(),extApiDefinitionMapper);
|
||||
num = getNextNum(optionData.get(0).getProjectId(), extApiDefinitionMapper);
|
||||
}
|
||||
//如果需要导入的数据为空。此时清空mock信息
|
||||
if (optionData.isEmpty()) {
|
||||
|
@ -259,34 +257,15 @@ public class ApiDefinitionImportUtilService {
|
|||
//如果EsbData需要存储,则需要进行接口是否更新的判断
|
||||
ApiDefinitionImportParamDTO apiDefinitionImportParam = new ApiDefinitionImportParamDTO(item, request, apiImport.getMocks(), toUpdateList, caseList);
|
||||
apiDefinitionImportParam.setRepeatList(sameRefIds);
|
||||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
String apiId = item.getId();
|
||||
EsbApiParamsWithBLOBs model = apiImport.getEsbApiParamsMap().get(apiId);
|
||||
request.setModeId("fullCoverage");//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||
|
||||
ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam);
|
||||
if (model != null) {
|
||||
apiImport.getEsbApiParamsMap().remove(apiId);
|
||||
model.setResourceId(item.getId());
|
||||
apiImport.getEsbApiParamsMap().put(item.getId(), model);
|
||||
}
|
||||
if (apiImportSendNoticeDTO != null) {
|
||||
apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO);
|
||||
}
|
||||
} else {
|
||||
ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam);
|
||||
if (apiImportSendNoticeDTO != null) {
|
||||
apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO);
|
||||
}
|
||||
ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam);
|
||||
if (apiImportSendNoticeDTO != null) {
|
||||
apiImportSendNoticeDTOS.add(apiImportSendNoticeDTO);
|
||||
}
|
||||
if (i % 300 == 0) {
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
}
|
||||
|
||||
//判断EsbData是否需要存储
|
||||
ApiDefinitionImportUtil.delEsbData(apiImport, sqlSession);
|
||||
|
||||
if (!CollectionUtils.isEmpty(apiImport.getMocks())) {
|
||||
MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class);
|
||||
mockConfigService.importMock(apiImport, sqlSession, request);
|
||||
|
@ -336,14 +315,14 @@ public class ApiDefinitionImportUtilService {
|
|||
//允许覆盖模块,用导入的重复数据的最后一条覆盖查询的所有重复数据; case 在覆盖的时候,是拼接到原来的case,name唯一;不覆盖,就用原来的
|
||||
if (fullCoverageApi) {
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap, null);
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
}
|
||||
} else {
|
||||
//覆盖但不覆盖模块
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
//过滤同一层级重复模块,导入文件没有新增接口无需创建接口模块
|
||||
moduleMap = judgeModuleMap(moduleMap, optionMap, repeatDataMap);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,null);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -387,12 +366,12 @@ public class ApiDefinitionImportUtilService {
|
|||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap, null);
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
}
|
||||
} else {
|
||||
//不覆盖模块
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,null);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -473,7 +452,7 @@ public class ApiDefinitionImportUtilService {
|
|||
private static void startCoverModule(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
|
||||
String updateVersionId, List<ApiTestCaseWithBLOBs> optionDataCases,
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
|
||||
//临时记录修改数据后导入的数据
|
||||
List<ApiDefinitionWithBLOBs> coverApiList = new ArrayList<>();
|
||||
//临时记录需要更新的系统数据
|
||||
|
@ -501,7 +480,6 @@ public class ApiDefinitionImportUtilService {
|
|||
buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases);
|
||||
}
|
||||
//在指定版本中更新接口内容并变更接口模块为当前导入选择的模块下创建导入文件中接口指定的模块
|
||||
updateEsb(esbApiParamsMap, definitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getId());
|
||||
ApiDefinitionWithBLOBs api = new ApiDefinitionWithBLOBs();
|
||||
BeanUtils.copyBean(api, apiDefinitionWithBLOBs);
|
||||
api.setId(definitionWithBLOBs.getId());
|
||||
|
@ -568,6 +546,7 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
return moduleMap;
|
||||
}
|
||||
|
||||
private static void addNewVersionApi(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs, ApiDefinitionWithBLOBs v, String version) {
|
||||
apiDefinitionWithBLOBs.setVersionId(version);
|
||||
apiDefinitionWithBLOBs.setNum(v.getNum());
|
||||
|
@ -726,7 +705,7 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
|
||||
private List<ApiDefinitionWithBLOBs> dealRepeat(ApiTestImportRequest request, List<ApiDefinitionWithBLOBs> optionData, Map<String, ApiModule> moduleMap, Boolean fullCoverage, Map<String, String> idPathMap, ApiModuleDTO chooseModule,
|
||||
Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap, List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiTestCaseWithBLOBs> optionDataCases) {
|
||||
List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiTestCaseWithBLOBs> optionDataCases) {
|
||||
String chooseModuleId = request.getModuleId();
|
||||
List<ApiDefinitionWithBLOBs> repeatApiDefinitionWithBLOBs = getApiDefinitionWithBLOBsList(request, optionData);
|
||||
//重复接口的case
|
||||
|
@ -758,11 +737,11 @@ public class ApiDefinitionImportUtilService {
|
|||
//处理数据
|
||||
if (fullCoverage) {
|
||||
if (fullCoverageApi) {
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap);
|
||||
startCoverModule(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
} else {
|
||||
//过滤同一层级重复模块,导入文件没有新增接口无需创建接口模块
|
||||
moduleMap = judgeModuleMap(moduleMap, optionMap, repeatDataMap);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
}
|
||||
} else {
|
||||
//不覆盖
|
||||
|
@ -776,7 +755,7 @@ public class ApiDefinitionImportUtilService {
|
|||
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getModulePath())));
|
||||
optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getModulePath()), api -> api));
|
||||
if (fullCoverage) {
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap,esbApiParamsMap);
|
||||
startCover(toUpdateList, optionData, optionMap, repeatDataMap, updateVersionId, optionDataCases, oldCaseMap);
|
||||
} else {
|
||||
//不覆盖,同一接口不做更新
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
|
@ -834,7 +813,7 @@ public class ApiDefinitionImportUtilService {
|
|||
private static void startCover(List<ApiDefinitionWithBLOBs> toUpdateList, List<ApiDefinitionWithBLOBs> optionData,
|
||||
Map<String, ApiDefinitionWithBLOBs> methodPathMap, Map<String, List<ApiDefinitionWithBLOBs>> repeatDataMap,
|
||||
String updateVersionId, List<ApiTestCaseWithBLOBs> optionDataCases,
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap) {
|
||||
List<ApiDefinitionWithBLOBs> coverApiList = new ArrayList<>();
|
||||
List<ApiDefinitionWithBLOBs> updateApiList = new ArrayList<>();
|
||||
repeatDataMap.forEach((k, v) -> {
|
||||
|
@ -853,7 +832,6 @@ public class ApiDefinitionImportUtilService {
|
|||
i += 1;
|
||||
continue;
|
||||
}
|
||||
updateEsb(esbApiParamsMap, definitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getId());
|
||||
//组合case
|
||||
if (MapUtils.isNotEmpty(caseNameMap)) {
|
||||
buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases);
|
||||
|
@ -868,7 +846,7 @@ public class ApiDefinitionImportUtilService {
|
|||
updateApiList.add(definitionWithBLOBs);
|
||||
}
|
||||
if (i == v.size()) {
|
||||
if (latestApi!=null) {
|
||||
if (latestApi != null) {
|
||||
boolean hasChange;
|
||||
if (apiDefinitionWithBLOBs.getProtocol().equals("HTTP")) {
|
||||
hasChange = ApiDefinitionImportUtil.checkIsSynchronize(latestApi, apiDefinitionWithBLOBs);
|
||||
|
@ -1029,19 +1007,6 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void updateEsb(Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap, String newId, String oldId) {
|
||||
if (MapUtils.isNotEmpty(esbApiParamsMap)) {
|
||||
EsbApiParamsWithBLOBs esbApiParamsWithBLOBs = esbApiParamsMap.get(oldId);
|
||||
if (esbApiParamsWithBLOBs != null) {
|
||||
esbApiParamsMap.remove(oldId);
|
||||
esbApiParamsWithBLOBs.setResourceId(newId);
|
||||
esbApiParamsMap.put(newId, esbApiParamsWithBLOBs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ApiImportSendNoticeDTO _importCreate(ApiDefinitionMapper batchMapper, ApiDefinitionImportParamDTO apiDefinitionImportParamDTO) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionImportParamDTO.getApiDefinition();
|
||||
ApiTestImportRequest apiTestImportRequest = apiDefinitionImportParamDTO.getApiTestImportRequest();
|
||||
|
@ -1151,8 +1116,6 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static List<ApiTestCaseWithBLOBs> setRequestAndAddNewCase(ApiDefinitionWithBLOBs apiDefinition, List<ApiTestCaseWithBLOBs> caseList, boolean newCreate) {
|
||||
boolean createCase = false;
|
||||
if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestTypeConstants.HTTP)) {
|
||||
|
|
|
@ -107,8 +107,6 @@ public class ApiDefinitionService {
|
|||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
@Resource
|
||||
private TcpApiParamService tcpApiParamService;
|
||||
@Resource
|
||||
private ApiModuleMapper apiModuleMapper;
|
||||
|
@ -131,8 +129,6 @@ public class ApiDefinitionService {
|
|||
@Resource
|
||||
private BaseProjectService baseProjectService;
|
||||
@Resource
|
||||
private EsbApiParamsMapper esbApiParamsMapper;
|
||||
@Resource
|
||||
private ApiExecutionInfoService apiExecutionInfoService;
|
||||
@Lazy
|
||||
@Resource
|
||||
|
@ -451,7 +447,6 @@ public class ApiDefinitionService {
|
|||
apiTestCaseService.deleteTestCase(api.getId());
|
||||
extApiDefinitionExecResultMapper.deleteByResourceId(api.getId());
|
||||
apiDefinitionMapper.deleteByPrimaryKey(api.getId());
|
||||
esbApiParamService.deleteByResourceId(api.getId());
|
||||
MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class);
|
||||
mockConfigService.deleteMockConfigByApiId(api.getId());
|
||||
// 删除自定义字段关联关系
|
||||
|
@ -474,7 +469,6 @@ public class ApiDefinitionService {
|
|||
public void deleteBatch(List<String> apiIds) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andIdIn(apiIds);
|
||||
esbApiParamService.deleteByResourceIdIn(apiIds);
|
||||
apiDefinitionMapper.deleteByExample(example);
|
||||
apiTestCaseService.deleteBatchByDefinitionId(apiIds);
|
||||
// 删除附件关系
|
||||
|
@ -720,10 +714,7 @@ public class ApiDefinitionService {
|
|||
|
||||
private ApiDefinitionWithBLOBs updateTest(SaveApiDefinitionRequest request) {
|
||||
checkNameExist(request, false);
|
||||
if (StringUtils.equals(request.getMethod(), "ESB")) {
|
||||
//ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据
|
||||
request = esbApiParamService.handleEsbRequest(request);
|
||||
} else if (StringUtils.equals(request.getMethod(), "TCP")) {
|
||||
if (StringUtils.equals(request.getMethod(), "TCP")) {
|
||||
request = tcpApiParamService.handleTcpRequest(request);
|
||||
}
|
||||
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs();
|
||||
|
@ -877,10 +868,6 @@ public class ApiDefinitionService {
|
|||
|
||||
private ApiDefinitionResult createTest(SaveApiDefinitionRequest request) {
|
||||
checkNameExist(request, false);
|
||||
if (StringUtils.equals(request.getMethod(), "ESB")) {
|
||||
//ESB的接口类型数据,采用TCP方式去发送。并将方法类型改为TCP。 并修改发送数据
|
||||
request = esbApiParamService.handleEsbRequest(request);
|
||||
}
|
||||
final ApiDefinitionWithBLOBs test = new ApiDefinitionWithBLOBs();
|
||||
test.setId(request.getId());
|
||||
test.setName(request.getName());
|
||||
|
@ -1304,9 +1291,6 @@ public class ApiDefinitionService {
|
|||
res.setCasePassingRate("-");
|
||||
res.setCaseStatus("-");
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) {
|
||||
esbApiParamService.handleApiEsbParams(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1561,25 +1545,6 @@ public class ApiDefinitionService {
|
|||
public String getLogDetails(String id) {
|
||||
ApiDefinitionWithBLOBs bloBs = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||
if (bloBs != null) {
|
||||
if (StringUtils.equals(bloBs.getMethod(), "ESB")) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdEqualTo(id);
|
||||
List<EsbApiParamsWithBLOBs> list = esbApiParamsMapper.selectByExampleWithBLOBs(example);
|
||||
JSONObject request = JSONUtil.parseObject(bloBs.getRequest());
|
||||
Object backEsbDataStruct = request.get("backEsbDataStruct");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (backEsbDataStruct != null) {
|
||||
map.put("backEsbDataStruct", backEsbDataStruct);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
map.put("backScript", list.get(0).getBackedScript());
|
||||
}
|
||||
map.put(PropertyConstant.TYPE, "ESB");
|
||||
}
|
||||
request.remove("backEsbDataStruct");
|
||||
bloBs.setRequest(request.toString());
|
||||
String response = JSON.toJSONString(map);
|
||||
bloBs.setResponse(response);
|
||||
}
|
||||
List<DetailColumn> columns = ReflexObjectUtil.getColumns(bloBs, DefinitionReference.definitionColumns);
|
||||
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns);
|
||||
return JSON.toJSONString(details);
|
||||
|
@ -1666,17 +1631,10 @@ public class ApiDefinitionService {
|
|||
ApiDefinitionResult result = null;
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
result = list.get(0);
|
||||
this.checkApiAttachInfo(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkApiAttachInfo(ApiDefinitionResult result) {
|
||||
if (StringUtils.equalsIgnoreCase("esb", result.getMethod())) {
|
||||
esbApiParamService.handleApiEsbParams(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long countEffectiveByProjectId(String projectId, String versionId) {
|
||||
if (StringUtils.isEmpty(projectId)) {
|
||||
|
|
|
@ -14,10 +14,8 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
|||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiModuleExample;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiModuleMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper;
|
||||
|
@ -668,8 +666,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (protocol.equals("HTTP")) {
|
||||
return dealHttp(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, urlRepeat, importCases);
|
||||
} else {
|
||||
Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap = apiImport.getEsbApiParamsMap();
|
||||
return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases, esbApiParamsMap);
|
||||
return delOtherProtocol(data, pidChildrenMap, idPathMap, idModuleMap, request, fullCoverage, importCases);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -677,7 +674,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
private UpdateApiModuleDTO delOtherProtocol(List<ApiDefinitionWithBLOBs> data,
|
||||
Map<String, List<ApiModule>> pidChildrenMap, Map<String, String> idPathMap,
|
||||
Map<String, ApiModuleDTO> idModuleMap, ApiTestImportRequest request,
|
||||
Boolean fullCoverage, List<ApiTestCaseWithBLOBs> importCases, Map<String, EsbApiParamsWithBLOBs> esbApiParamsMap) {
|
||||
Boolean fullCoverage, List<ApiTestCaseWithBLOBs> importCases) {
|
||||
List<ApiDefinitionWithBLOBs> optionData = new ArrayList<>();
|
||||
//去重,TCP,SQL,DUBBO 模块下名称唯一
|
||||
removeRepeatOrigin(data, fullCoverage, optionData);
|
||||
|
@ -735,11 +732,6 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (fullCoverage == null) {
|
||||
fullCoverage = false;
|
||||
}
|
||||
|
||||
//标准版ESB数据导入不区分是否覆盖,默认都为覆盖
|
||||
if (apiImport.getEsbApiParamsMap() != null) {
|
||||
fullCoverage = true;
|
||||
}
|
||||
return fullCoverage;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,6 @@ public class ApiTestCaseService {
|
|||
@Resource
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
@Resource
|
||||
private ExtApiScenarioMapper extApiScenarioMapper;
|
||||
@Resource
|
||||
private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
|
||||
|
@ -125,13 +123,7 @@ public class ApiTestCaseService {
|
|||
moduleIds.add(request.getModuleId());
|
||||
request.setModuleIds(moduleIds);
|
||||
}
|
||||
List<ApiTestCaseResult> returnList = extApiTestCaseMapper.list(request);
|
||||
for (ApiTestCaseResult res : returnList) {
|
||||
if (StringUtils.equalsIgnoreCase(res.getApiMethod(), "esb")) {
|
||||
esbApiParamService.handleApiEsbParams(res);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
return extApiTestCaseMapper.list(request);
|
||||
}
|
||||
|
||||
public List<ApiTestCase> selectByIds(ApiTestCaseRequest request) {
|
||||
|
@ -281,13 +273,7 @@ public class ApiTestCaseService {
|
|||
}
|
||||
|
||||
public ApiTestCaseInfo get(String id) {
|
||||
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id);
|
||||
if (model != null) {
|
||||
if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) {
|
||||
esbApiParamService.handleApiEsbParams(model);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
return extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public ApiTestCaseInfo getResult(String id) {
|
||||
|
@ -332,7 +318,6 @@ public class ApiTestCaseService {
|
|||
testPlanApiCaseService.deleteByCaseId(testId);
|
||||
extApiDefinitionExecResultMapper.deleteByResourceId(testId);
|
||||
apiTestCaseMapper.deleteByPrimaryKey(testId);
|
||||
esbApiParamService.deleteByResourceId(testId);
|
||||
// 删除附件关系
|
||||
extFileAssociationService.deleteByResourceId(testId);
|
||||
deleteFollows(testId);
|
||||
|
@ -404,10 +389,6 @@ public class ApiTestCaseService {
|
|||
private ApiTestCase updateTest(SaveApiTestCaseRequest request) {
|
||||
checkNameExist(request);
|
||||
request.setRequest(tcpApiParamService.parseMsTestElement(request.getRequest()));
|
||||
if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
|
||||
request = esbApiParamService.handleEsbRequest(request);
|
||||
}
|
||||
|
||||
final ApiTestCaseWithBLOBs test = apiTestCaseMapper.selectByPrimaryKey(request.getId());
|
||||
if (test != null) {
|
||||
test.setName(request.getName());
|
||||
|
@ -460,9 +441,6 @@ public class ApiTestCaseService {
|
|||
checkNameExist(request);
|
||||
FileUtils.createBodyFiles(request.getId(), bodyFiles);
|
||||
request.setRequest(tcpApiParamService.parseMsTestElement(request.getRequest()));
|
||||
if (StringUtils.isNotEmpty(request.getEsbDataStruct()) || StringUtils.isNotEmpty(request.getBackEsbDataStruct())) {
|
||||
request = esbApiParamService.handleEsbRequest(request);
|
||||
}
|
||||
FileUtils.copyBdyFile(request.getApiDefinitionId(), request.getId());
|
||||
|
||||
final ApiTestCaseWithBLOBs test = new ApiTestCaseWithBLOBs();
|
||||
|
@ -631,11 +609,6 @@ public class ApiTestCaseService {
|
|||
|
||||
public Map<String, String> getRequest(ApiTestCaseRequest request) {
|
||||
List<ApiTestCaseInfo> list = extApiTestCaseMapper.getRequest(request);
|
||||
for (ApiTestCaseInfo model : list) {
|
||||
if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) {
|
||||
esbApiParamService.handleApiEsbParams(model);
|
||||
}
|
||||
}
|
||||
return list.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, ApiTestCaseWithBLOBs::getRequest));
|
||||
}
|
||||
|
||||
|
@ -822,11 +795,6 @@ public class ApiTestCaseService {
|
|||
} else {
|
||||
list = extApiTestCaseMapper.getCaseInfo(request);
|
||||
}
|
||||
for (ApiTestCaseInfo model : list) {
|
||||
if (StringUtils.equalsIgnoreCase(model.getApiMethod(), "esb")) {
|
||||
esbApiParamService.handleApiEsbParams(model);
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||
|
|
|
@ -1,354 +0,0 @@
|
|||
package io.metersphere.service.definition;
|
||||
|
||||
import io.metersphere.api.dto.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.automation.SaveApiScenarioRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.SaveApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.parse.scenario.EsbDataParser;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.EsbApiParamsExample;
|
||||
import io.metersphere.base.domain.EsbApiParamsWithBLOBs;
|
||||
import io.metersphere.base.mapper.EsbApiParamsMapper;
|
||||
import io.metersphere.commons.utils.JSON;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.commons.utils.JSONUtil;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/16 4:57 下午
|
||||
* @Description
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class EsbApiParamService {
|
||||
@Resource
|
||||
private EsbApiParamsMapper esbApiParamsMapper;
|
||||
|
||||
public EsbApiParamsWithBLOBs createEsbApiParam(String resourceId, String esbDataStruct, String backedEsbDataStrcut, String backedScript) {
|
||||
EsbApiParamsWithBLOBs model = null;
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
List<EsbApiParamsWithBLOBs> list = esbApiParamsMapper.selectByExampleWithBLOBs(example);
|
||||
if (list.isEmpty()) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
model = new EsbApiParamsWithBLOBs();
|
||||
model.setId(uuid);
|
||||
model.setResourceId(resourceId);
|
||||
model.setDataStruct(esbDataStruct);
|
||||
model.setResponseDataStruct(backedEsbDataStrcut);
|
||||
model.setBackedScript(backedScript);
|
||||
esbApiParamsMapper.insert(model);
|
||||
} else {
|
||||
model = list.get(0);
|
||||
model.setDataStruct(esbDataStruct);
|
||||
model.setResponseDataStruct(backedEsbDataStrcut);
|
||||
model.setBackedScript(backedScript);
|
||||
esbApiParamsMapper.updateByPrimaryKeyWithBLOBs(model);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public EsbApiParamsWithBLOBs getEsbParamBLOBsByResourceID(String resourceId) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
List<EsbApiParamsWithBLOBs> list = esbApiParamsMapper.selectByExampleWithBLOBs(example);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByResourceId(String resourceId) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdEqualTo(resourceId);
|
||||
esbApiParamsMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void handleApiEsbParams(ApiDefinitionResult res) {
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId());
|
||||
if (esbParamBlobs == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(res.getRequest())) {
|
||||
JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest());
|
||||
if (jsonObj != null) {
|
||||
res.setRequest(jsonObj.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void handleApiEsbParams(ApiTestCaseWithBLOBs res) {
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId());
|
||||
if (esbParamBlobs == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(res.getRequest())) {
|
||||
JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest());
|
||||
if (jsonObj != null) {
|
||||
res.setRequest(jsonObj.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject addEsbInfoToJsonString(EsbApiParamsWithBLOBs esbParamBlobs, String requestString) {
|
||||
JSONObject returnObj = null;
|
||||
try {
|
||||
returnObj = JSONUtil.parseObject(requestString);
|
||||
JSONArray esbDataArray = JSONUtil.parseArray(esbParamBlobs.getDataStruct());
|
||||
if (esbDataArray == null) {
|
||||
returnObj.put("esbDataStruct", StringUtils.EMPTY);
|
||||
} else {
|
||||
returnObj.put("esbDataStruct", esbDataArray);
|
||||
}
|
||||
JSONArray responseDataArray = JSONUtil.parseArray(esbParamBlobs.getResponseDataStruct());
|
||||
if (responseDataArray == null) {
|
||||
returnObj.put("backEsbDataStruct", StringUtils.EMPTY);
|
||||
} else {
|
||||
returnObj.put("backEsbDataStruct", responseDataArray);
|
||||
}
|
||||
returnObj.put("esbFrontedScript", esbParamBlobs.getFrontedScript());
|
||||
JSONObject backedScriptObj = JSONUtil.parseObject(esbParamBlobs.getBackedScript());
|
||||
returnObj.put("backScript", backedScriptObj);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
public void handleApiEsbParams(ApiTestCaseResult res) {
|
||||
if (res == null) {
|
||||
return;
|
||||
}
|
||||
EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId());
|
||||
if (esbParamBlobs == null) {
|
||||
return;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(res.getRequest())) {
|
||||
JSONObject jsonObj = this.addEsbInfoToJsonString(esbParamBlobs, res.getRequest());
|
||||
if (jsonObj != null) {
|
||||
res.setRequest(jsonObj.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public SaveApiDefinitionRequest updateEsbRequest(SaveApiDefinitionRequest request) {
|
||||
try {
|
||||
//修改request.parameters
|
||||
//用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。
|
||||
//业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点)
|
||||
//代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml
|
||||
if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
|
||||
MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest();
|
||||
List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
request.setRequest(tcpSampler);
|
||||
}
|
||||
//更新EsbApiParams类
|
||||
// EsbApiParamsWithBLOBs esbApiParams = this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public SaveApiDefinitionRequest handleEsbRequest(SaveApiDefinitionRequest request) {
|
||||
try {
|
||||
//修改request.parameters
|
||||
//用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。
|
||||
//业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点)
|
||||
//代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml
|
||||
if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
|
||||
MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest();
|
||||
tcpSampler.setProtocol("ESB");
|
||||
List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
//更新EsbApiParams类
|
||||
this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
// public RunDefinitionRequest handleEsbRequest(RunDefinitionRequest request) {
|
||||
// try {
|
||||
// //修改request.parameters
|
||||
// //用户交互感受:ESB的发送数据以报文模板为主框架,同时前端不再有key-value的表格数据填充。
|
||||
// //业务逻辑: 发送ESB接口数据时,使用报文模板中的数据,同时报文模板中的${取值}目的是为了拼接数据结构(比如xml的子节点)
|
||||
// //代码实现: 此处打算解析前端传来的EsbDataStruct数据结构,将数据结构按照报文模板中的${取值}为最高优先级组装keyValue对象。这样Jmeter会自动拼装为合适的xml
|
||||
// if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
|
||||
// if(request.getTestElement() instanceof MsTestPlan){
|
||||
// MsTestPlan testPlan = (MsTestPlan)request.getTestElement();
|
||||
// for (MsTestElement testElement: testPlan.getHashTree()) {
|
||||
// if(testElement instanceof MsThreadGroup){
|
||||
// MsThreadGroup group = (MsThreadGroup)testElement;
|
||||
// for (MsTestElement groupElement: testPlan.getHashTree()) {
|
||||
// if(groupElement instanceof MsScenario){
|
||||
// MsScenario scenario = (MsScenario)groupElement;
|
||||
// for (MsTestElement scenarioElement: scenario.getHashTree()) {
|
||||
// if(scenarioElement instanceof MsTCPSampler){
|
||||
// MsTCPSampler tcpSampler = (MsTCPSampler) scenarioElement;
|
||||
// List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct());
|
||||
// tcpSampler.setParameters(keyValueList);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //更新EsbApiParams类
|
||||
// EsbApiParamsWithBLOBs esbApiParams = this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackScript());
|
||||
// } catch (Exception e) {
|
||||
// LogUtil.error(e);
|
||||
// }
|
||||
// return request;
|
||||
// }
|
||||
|
||||
//通过esb数据结构生成keyValue集合,以及发送参数
|
||||
public List<KeyValue> genKeyValueListByDataStruct(MsTCPSampler tcpSampler, String esbDataStruct) {
|
||||
List<KeyValue> keyValueList = new ArrayList<>();
|
||||
String sendRequest = tcpSampler.getRequest();
|
||||
String paramRegexStr = "\\$\\{([^}]*)\\}";
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(sendRequest)) {
|
||||
List<String> paramList = new ArrayList<>();
|
||||
List<EsbDataStruct> dataStructRequestList = JSON.parseArray(esbDataStruct, EsbDataStruct.class);
|
||||
Pattern regex = Pattern.compile(paramRegexStr);
|
||||
Matcher matcher = regex.matcher(sendRequest);
|
||||
while (matcher.find()) {
|
||||
paramList.add(matcher.group(1));
|
||||
}
|
||||
for (String param : paramList) {
|
||||
String value = this.genValueFromEsbDataStructByParam(dataStructRequestList, param);
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
KeyValue kv = new KeyValue();
|
||||
kv.setName(param);
|
||||
kv.setValue(value);
|
||||
kv.setRequired(true);
|
||||
keyValueList.add(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return keyValueList;
|
||||
}
|
||||
|
||||
public List<KeyValue> genKeyValueListByDataStruct(MsTCPSampler tcpSampler, List<EsbDataStruct> dataStructRequestList) {
|
||||
List<KeyValue> keyValueList = new ArrayList<>();
|
||||
String sendRequest = tcpSampler.getRequest();
|
||||
String paramRegexStr = "\\$\\{([^}]*)\\}";
|
||||
try {
|
||||
if (StringUtils.isNotEmpty(sendRequest)) {
|
||||
List<String> paramList = new ArrayList<>();
|
||||
Pattern regex = Pattern.compile(paramRegexStr);
|
||||
Matcher matcher = regex.matcher(sendRequest);
|
||||
while (matcher.find()) {
|
||||
paramList.add(matcher.group(1));
|
||||
}
|
||||
for (String param : paramList) {
|
||||
String value = this.genValueFromEsbDataStructByParam(dataStructRequestList, param);
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
KeyValue kv = new KeyValue();
|
||||
kv.setName(param);
|
||||
kv.setValue(value);
|
||||
kv.setRequired(true);
|
||||
keyValueList.add(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return keyValueList;
|
||||
}
|
||||
|
||||
//通过报文模版中的变量参数,解析报文数据结构,生成对应的xml数据
|
||||
private String genValueFromEsbDataStructByParam(List<EsbDataStruct> dataStructRequestList, String param) {
|
||||
String returnValue = StringUtils.EMPTY;
|
||||
if (StringUtils.isNotEmpty(param)) {
|
||||
//多层结构使用"."来表示。aaa.bb.cc 代表的是dataStructRequestList中,aaa节点下,bb节点下的cc节点数据
|
||||
String[] paramArr = param.split("\\.");
|
||||
returnValue = EsbDataParser.esbData2XmlByParamStruct(dataStructRequestList, paramArr);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public SaveApiTestCaseRequest handleEsbRequest(SaveApiTestCaseRequest request) {
|
||||
try {
|
||||
//修改request.parameters, 将树结构类型数据转化为表格类型数据,供执行时参数的提取
|
||||
if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
|
||||
MsTCPSampler tcpSampler = (MsTCPSampler) request.getRequest();
|
||||
List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, request.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
//更新EsbApiParams类
|
||||
this.createEsbApiParam(request.getId(), request.getEsbDataStruct(), request.getBackEsbDataStruct(), request.getBackEsbDataStruct());
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public void handleEsbRequest(MsTCPSampler tcpSampler) {
|
||||
try {
|
||||
//修改request.parameters, 将树结构类型数据转化为表格类型数据,供执行时参数的提取
|
||||
if (tcpSampler.getEsbDataStruct() != null) {
|
||||
List<KeyValue> keyValueList = this.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByResourceIdIn(List<String> apiIds) {
|
||||
EsbApiParamsExample example = new EsbApiParamsExample();
|
||||
example.createCriteria().andResourceIdIn(apiIds);
|
||||
esbApiParamsMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void checkScenarioRequests(SaveApiScenarioRequest request) {
|
||||
if (request.getScenarioDefinition() != null) {
|
||||
List<MsTestElement> hashTreeList = request.getScenarioDefinition().getHashTree();
|
||||
for (MsTestElement testElement : hashTreeList) {
|
||||
if (testElement instanceof MsTCPSampler) {
|
||||
this.handleEsbRequest((MsTCPSampler) testElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package io.metersphere.service.definition;
|
||||
|
||||
import io.metersphere.api.parse.api.ESBParser;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author song.tianyang
|
||||
* @Date 2021/3/22 7:02 下午
|
||||
* @Description
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class EsbImportService {
|
||||
|
||||
public void templateExport(HttpServletResponse response) {
|
||||
try {
|
||||
ESBParser.export(response, "EsbTemplate");
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,17 +3,14 @@ package io.metersphere.service.definition;
|
|||
import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
|
||||
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.parse.scenario.TcpTreeTableDataParser;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.plugin.core.MsTestElement;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -24,8 +21,6 @@ import java.util.List;
|
|||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TcpApiParamService {
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
|
||||
public SaveApiDefinitionRequest handleTcpRequest(SaveApiDefinitionRequest request) {
|
||||
MsTCPSampler tcpSampler = this.handleTcpRequest(request.getRequest());
|
||||
|
@ -56,27 +51,19 @@ public class TcpApiParamService {
|
|||
try {
|
||||
if (testElement instanceof MsTCPSampler) {
|
||||
tcpSampler = (MsTCPSampler) testElement;
|
||||
String protocol = tcpSampler.getProtocol();
|
||||
if (StringUtils.equalsIgnoreCase(protocol, "esb")) {
|
||||
if (CollectionUtils.isNotEmpty(tcpSampler.getEsbDataStruct())) {
|
||||
List<KeyValue> keyValueList = esbApiParamService.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct());
|
||||
tcpSampler.setParameters(keyValueList);
|
||||
}
|
||||
} else {
|
||||
String reportType = tcpSampler.getReportType();
|
||||
if (StringUtils.isNotEmpty(reportType)) {
|
||||
switch (reportType) {
|
||||
case "raw":
|
||||
tcpSampler.setRequest(tcpSampler.getRawDataStruct());
|
||||
break;
|
||||
case "xml":
|
||||
String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct());
|
||||
tcpSampler.setRequest(xmlDataStruct);
|
||||
break;
|
||||
case "json":
|
||||
tcpSampler.setRequest(tcpSampler.getJsonDataStruct());
|
||||
break;
|
||||
}
|
||||
String reportType = tcpSampler.getReportType();
|
||||
if (StringUtils.isNotEmpty(reportType)) {
|
||||
switch (reportType) {
|
||||
case "raw":
|
||||
tcpSampler.setRequest(tcpSampler.getRawDataStruct());
|
||||
break;
|
||||
case "xml":
|
||||
String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct());
|
||||
tcpSampler.setRequest(xmlDataStruct);
|
||||
break;
|
||||
case "json":
|
||||
tcpSampler.setRequest(tcpSampler.getJsonDataStruct());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ import io.metersphere.request.ResetOrderRequest;
|
|||
import io.metersphere.sechedule.ApiScenarioTestJob;
|
||||
import io.metersphere.sechedule.SwaggerUrlImportJob;
|
||||
import io.metersphere.service.*;
|
||||
import io.metersphere.service.definition.EsbApiParamService;
|
||||
import io.metersphere.service.definition.TcpApiParamService;
|
||||
import io.metersphere.service.ext.ExtApiScheduleService;
|
||||
import io.metersphere.service.ext.ExtFileAssociationService;
|
||||
|
@ -109,8 +108,6 @@ public class ApiScenarioService {
|
|||
@Resource
|
||||
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||
@Resource
|
||||
private EsbApiParamService esbApiParamService;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ApiScenarioEnvService apiScenarioEnvService;
|
||||
|
@ -287,8 +284,6 @@ public class ApiScenarioService {
|
|||
scenario.setOrder(ServiceUtils.getNextOrder(scenario.getProjectId(), extApiScenarioMapper::getLastOrder));
|
||||
scenario.setRefId(request.getId());
|
||||
scenario.setLatest(true);
|
||||
//检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。
|
||||
esbApiParamService.checkScenarioRequests(request);
|
||||
|
||||
apiScenarioMapper.insert(scenario);
|
||||
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||
|
@ -360,9 +355,6 @@ public class ApiScenarioService {
|
|||
public ApiScenario update(SaveApiScenarioRequest request, List<MultipartFile> bodyFiles, List<MultipartFile> scenarioFiles) {
|
||||
checkNameExist(request, false);
|
||||
checkScenarioNum(request);
|
||||
|
||||
//检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。
|
||||
esbApiParamService.checkScenarioRequests(request);
|
||||
//如果场景有TCP步骤的话,也要做参数计算处理
|
||||
tcpApiParamService.checkTestElement(request.getScenarioDefinition());
|
||||
final ApiScenarioWithBLOBs scenario = buildSaveScenario(request);
|
||||
|
|
|
@ -171,8 +171,3 @@ export function createDefinition(file, files, params) {
|
|||
let url = '/api/definition/create';
|
||||
return fileUpload(url, file, files, params);
|
||||
}
|
||||
|
||||
export function exportEsbTemp(name) {
|
||||
let url = '/api/definition/export-esb-template';
|
||||
return fileDownload(url, name);
|
||||
}
|
||||
|
|
|
@ -30,18 +30,20 @@
|
|||
<i class="el-icon-warning" />
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span v-xpack v-if="request.versionEnable && showVersion"
|
||||
>{{ $t('project.version.name') }}: {{ request.versionName }}</span
|
||||
>
|
||||
<span v-xpack v-if="request.versionEnable && showVersion">
|
||||
{{ $t('project.version.name') }}: {{ request.versionName }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template v-slot:behindHeaderLeft>
|
||||
<el-tag size="small" class="ms-tag" v-if="request.referenced === 'Deleted'" type="danger">
|
||||
{{ $t('api_test.automation.reference_deleted') }}
|
||||
</el-tag>
|
||||
<el-tag size="small" class="ms-tag" v-if="request.referenced === 'Copy'">{{ $t('commons.copy') }}</el-tag>
|
||||
<el-tag size="small" class="ms-tag" v-if="request.referenced === 'REF'"
|
||||
>{{ $t('api_test.scenario.reference') }}
|
||||
<el-tag size="small" class="ms-tag" v-if="request.referenced === 'Copy'">
|
||||
{{ $t('commons.copy') }}
|
||||
</el-tag>
|
||||
<el-tag size="small" class="ms-tag" v-if="request.referenced === 'REF'">
|
||||
{{ $t('api_test.scenario.reference') }}
|
||||
</el-tag>
|
||||
<span class="ms-tag ms-step-name-api">{{ getProjectName(request.projectId) }}</span>
|
||||
</template>
|
||||
|
@ -118,17 +120,8 @@
|
|||
:headers="request.headers"
|
||||
:is-read-only="isCompReadOnly"
|
||||
:request="request" />
|
||||
<mx-esb-definition
|
||||
v-if="request.esbDataStruct != null"
|
||||
v-xpack
|
||||
:request="request"
|
||||
:response="response"
|
||||
:showScript="true"
|
||||
:show-pre-script="true"
|
||||
:is-read-only="isCompReadOnly"
|
||||
ref="esbDefinition" />
|
||||
<ms-tcp-format-parameters
|
||||
v-if="(request.protocol === 'TCP' || request.type === 'TCPSampler') && request.esbDataStruct == null"
|
||||
v-if="request.protocol === 'TCP' || request.protocol === 'ESB' || request.type === 'TCPSampler'"
|
||||
:is-read-only="isCompReadOnly"
|
||||
:response="response"
|
||||
:show-pre-script="true"
|
||||
|
@ -158,36 +151,24 @@
|
|||
<template v-slot:result>
|
||||
<div v-loading="loading">
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<div v-if="request.backEsbDataStruct != null">
|
||||
<mx-esb-definition-response
|
||||
:currentProtocol="request.protocol"
|
||||
:request="request"
|
||||
:is-api-component="false"
|
||||
:show-options-button="false"
|
||||
:show-header="true"
|
||||
:result="request.requestResult"
|
||||
v-xpack />
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-tabs
|
||||
v-model="request.activeName"
|
||||
closable
|
||||
class="ms-tabs"
|
||||
v-if="request.requestResult && request.requestResult.length > 1">
|
||||
<el-tab-pane
|
||||
v-for="(item, i) in request.requestResult"
|
||||
:label="'循环' + (i + 1)"
|
||||
:key="i"
|
||||
style="margin-bottom: 5px">
|
||||
<api-response-component :currentProtocol="request.protocol" :apiActive="true" :result="item" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<api-response-component
|
||||
:currentProtocol="request.protocol"
|
||||
:apiActive="true"
|
||||
:result="request.requestResult[0]"
|
||||
v-else />
|
||||
</div>
|
||||
<el-tabs
|
||||
v-model="request.activeName"
|
||||
closable
|
||||
class="ms-tabs"
|
||||
v-if="request.requestResult && request.requestResult.length > 1">
|
||||
<el-tab-pane
|
||||
v-for="(item, i) in request.requestResult"
|
||||
:label="'循环' + (i + 1)"
|
||||
:key="i"
|
||||
style="margin-bottom: 5px">
|
||||
<api-response-component :currentProtocol="request.protocol" :apiActive="true" :result="item" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<api-response-component
|
||||
:currentProtocol="request.protocol"
|
||||
:apiActive="true"
|
||||
:result="request.requestResult[0]"
|
||||
v-else />
|
||||
</div>
|
||||
</template>
|
||||
</api-base-component>
|
||||
|
@ -257,8 +238,6 @@ export default {
|
|||
MsApiRequestForm: () => import('../../../definition/components/request/http/ApiHttpRequestForm'),
|
||||
MsRequestResultTail: () => import('../../../definition/components/response/RequestResultTail'),
|
||||
MsRun: () => import('../../../definition/components/Run'),
|
||||
MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'),
|
||||
MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -278,6 +257,7 @@ export default {
|
|||
};
|
||||
},
|
||||
created() {
|
||||
this.request.protocol = this.request.protocol === 'ESB' ? 'TCP' : this.request.protocol;
|
||||
// 历史数据兼容
|
||||
if (!this.request.requestResult) {
|
||||
this.request.requestResult = [{ responseResult: {} }];
|
||||
|
|
|
@ -79,10 +79,7 @@ export function getProtocolFilter(protocolType) {
|
|||
{ text: 'CONNECT', value: 'CONNECT' },
|
||||
];
|
||||
} else if (protocolType === 'TCP') {
|
||||
return [
|
||||
{ text: 'TCP', value: 'TCP' },
|
||||
{ text: 'ESB', value: 'ESB' },
|
||||
];
|
||||
return [{ text: 'TCP', value: 'TCP' }];
|
||||
} else if (protocolType === 'SQL') {
|
||||
return [{ text: 'SQL', value: 'SQL' }];
|
||||
} else if (protocolType === 'DUBBO') {
|
||||
|
|
|
@ -111,6 +111,7 @@ export default {
|
|||
this.$EventBus.$off('showXpackCaseBtn');
|
||||
},
|
||||
created() {
|
||||
this.api.method = this.api.method === 'ESB' ? 'TCP' : this.api.method;
|
||||
this.isXpack = !!hasLicense();
|
||||
if (this.isXpack) {
|
||||
this.$EventBus.$on('showXpackCaseBtn', (showUpdateRule) => {
|
||||
|
|
|
@ -183,16 +183,7 @@
|
|||
:show-pre-script="true"
|
||||
:request="apiCase.request"
|
||||
:response="apiCase.responseData"
|
||||
v-if="api.method === 'TCP'" />
|
||||
<mx-esb-definition
|
||||
class="esb-div"
|
||||
v-xpack
|
||||
:request="apiCase.request"
|
||||
:show-pre-script="true"
|
||||
:showScript="true"
|
||||
:response="apiCase.responseData"
|
||||
v-if="api.method === 'ESB'"
|
||||
ref="esbDefinition" />
|
||||
v-if="api.method === 'TCP' || api.method === 'ESB'" />
|
||||
<ms-sql-basis-parameters
|
||||
:showScript="true"
|
||||
:request="apiCase.request"
|
||||
|
@ -205,22 +196,10 @@
|
|||
v-if="api.protocol === 'DUBBO'" />
|
||||
<!-- HTTP 请求返回数据 -->
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<div v-if="api.method === 'ESB'">
|
||||
<mx-esb-definition-response
|
||||
v-xpack
|
||||
:currentProtocol="apiCase.request.protocol"
|
||||
:request="apiCase.request"
|
||||
:is-api-component="false"
|
||||
:show-options-button="false"
|
||||
:show-header="true"
|
||||
:api-item="apiCase" />
|
||||
</div>
|
||||
<div v-else>
|
||||
<api-response-component
|
||||
:currentProtocol="apiCase.request.protocol"
|
||||
:api-item="apiCase"
|
||||
:result="apiCase.responseData" />
|
||||
</div>
|
||||
<api-response-component
|
||||
:currentProtocol="apiCase.request.protocol"
|
||||
:api-item="apiCase"
|
||||
:result="apiCase.responseData" />
|
||||
</div>
|
||||
</el-collapse-transition>
|
||||
<ms-change-history ref="changeHistory" />
|
||||
|
@ -334,8 +313,6 @@ export default {
|
|||
MsChangeHistory,
|
||||
ApiCaseHeader,
|
||||
MsApiReportStatus: () => import('../../../automation/report/ApiReportStatus'),
|
||||
MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'),
|
||||
MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
|
|
@ -12,19 +12,9 @@
|
|||
<ms-form-divider :title="$t('test_track.plan_view.base_info')" />
|
||||
|
||||
<!-- 基础信息 -->
|
||||
<el-row>
|
||||
<el-form-item v-if="currentProtocol !== 'TCP'" :label="$t('commons.name')" prop="name">
|
||||
<el-input v-model="basicForm.name" class="ms-http-input" size="small" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-else :label="$t('commons.name')" prop="name">
|
||||
<el-input v-model="basicForm.name" class="ms-http-input" size="small">
|
||||
<el-select slot="prepend" v-model="basicForm.method" size="mini" style="width: 80px">
|
||||
<el-option v-for="item in methodTypes" :key="item.key" :label="item.value" :value="item.key" />
|
||||
</el-select>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-row>
|
||||
<el-form-item :label="$t('commons.name')" prop="name">
|
||||
<el-input v-model="basicForm.name" class="ms-http-input" size="small" />
|
||||
</el-form-item>
|
||||
|
||||
<el-row>
|
||||
<el-form-item :label="$t('api_test.definition.request.responsible')" prop="userId">
|
||||
|
@ -272,14 +262,6 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.basicForm = this.form;
|
||||
if (hasLicense()) {
|
||||
if (this.methodTypes.length == 1) {
|
||||
let esbMethodType = {};
|
||||
esbMethodType.key = 'ESB';
|
||||
esbMethodType.value = 'ESB';
|
||||
this.methodTypes.push(esbMethodType);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -52,20 +52,12 @@
|
|||
</el-row>
|
||||
|
||||
<!-- 请求参数 -->
|
||||
<div v-if="apiProtocol == 'TCP'">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<ms-tcp-format-parameters
|
||||
:show-pre-script="true"
|
||||
:show-script="false"
|
||||
:request="request"
|
||||
ref="tcpFormatParameter" />
|
||||
</div>
|
||||
<div v-else-if="apiProtocol == 'ESB'">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<mx-esb-definition v-xpack :show-pre-script="true" :show-script="false" :request="request" ref="esbDefinition" />
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<mx-esb-definition-response v-xpack :is-api-component="true" :show-options-button="true" :request="request" />
|
||||
</div>
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<ms-tcp-format-parameters
|
||||
:show-pre-script="true"
|
||||
:show-script="false"
|
||||
:request="request"
|
||||
ref="tcpFormatParameter" />
|
||||
<api-other-info :api="basisData" ref="apiOtherInfo" />
|
||||
|
||||
<ms-change-history ref="changeHistory" />
|
||||
|
@ -112,7 +104,8 @@ import {
|
|||
delDefinitionByRefId,
|
||||
getDefinitionById,
|
||||
getDefinitionByIdAndRefId,
|
||||
getDefinitionVersions, updateDefinitionFollows,
|
||||
getDefinitionVersions,
|
||||
updateDefinitionFollows,
|
||||
} from '@/api/definition';
|
||||
import MsTcpBasicApi from './TCPBasicApi';
|
||||
import MsTcpFormatParameters from '../request/tcp/TcpFormatParameters';
|
||||
|
@ -125,8 +118,8 @@ import { createComponent } from '.././jmeter/components';
|
|||
import { TYPE_TO_C } from '@/business/automation/scenario/Setting';
|
||||
import MsDialogFooter from 'metersphere-frontend/src/components/MsDialogFooter';
|
||||
import { useApiStore } from '@/store';
|
||||
import {apiTestCaseCount} from '@/api/api-test-case';
|
||||
import {getDefaultVersion, setLatestVersionById} from 'metersphere-frontend/src/api/version';
|
||||
import { apiTestCaseCount } from '@/api/api-test-case';
|
||||
import { getDefaultVersion, setLatestVersionById } from 'metersphere-frontend/src/api/version';
|
||||
|
||||
const store = useApiStore();
|
||||
const { Body } = require('@/business/definition/model/ApiTestModel');
|
||||
|
@ -140,9 +133,7 @@ export default {
|
|||
MsTcpFormatParameters,
|
||||
MsChangeHistory,
|
||||
TCPApiVersionDiff,
|
||||
MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'),
|
||||
MxVersionHistory: () => import('metersphere-frontend/src/components/version/MxVersionHistory'),
|
||||
MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'),
|
||||
},
|
||||
props: {
|
||||
request: {},
|
||||
|
@ -175,7 +166,7 @@ export default {
|
|||
newApiProtocol: 'TCP',
|
||||
createNewVersionVisible: false,
|
||||
latestVersionId: '',
|
||||
hasLatest: false
|
||||
hasLatest: false,
|
||||
};
|
||||
},
|
||||
created: function () {
|
||||
|
@ -186,14 +177,6 @@ export default {
|
|||
if (this.apiProtocol == null || this.apiProtocol == '') {
|
||||
this.apiProtocol = 'TCP';
|
||||
}
|
||||
if (hasLicense()) {
|
||||
if (this.methodTypes.length == 1) {
|
||||
let esbMethodType = {};
|
||||
esbMethodType.key = 'ESB';
|
||||
esbMethodType.value = 'ESB';
|
||||
this.methodTypes.push(esbMethodType);
|
||||
}
|
||||
}
|
||||
definitionFollow(this.basisData.id).then((response) => {
|
||||
this.basisData.follows = response.data;
|
||||
for (let i = 0; i < response.data.length; i++) {
|
||||
|
@ -244,25 +227,9 @@ export default {
|
|||
if (this.basisData.tags instanceof Array) {
|
||||
this.basisData.tags = JSON.stringify(this.basisData.tags);
|
||||
}
|
||||
if (this.basisData.method === 'ESB') {
|
||||
let validataResult = this.$refs.esbDefinition.validateEsbDataStruct(this.request.esbDataStruct);
|
||||
if (!validataResult) {
|
||||
return;
|
||||
}
|
||||
if (this.request.esbDataStruct != null) {
|
||||
this.esbDataStruct = JSON.stringify(this.request.esbDataStruct);
|
||||
this.basisData.esbDataStruct = this.esbDataStruct;
|
||||
}
|
||||
if (this.request.backEsbDataStruct != null) {
|
||||
this.basisData.backEsbDataStruct = JSON.stringify(this.request.backEsbDataStruct);
|
||||
}
|
||||
if (this.request.backScript != null) {
|
||||
this.basisData.backScript = JSON.stringify(this.request.backScript);
|
||||
}
|
||||
} else {
|
||||
if (this.$refs.tcpFormatParameter) {
|
||||
this.$refs.tcpFormatParameter.validateXmlDataStruct();
|
||||
}
|
||||
|
||||
if (this.$refs.tcpFormatParameter) {
|
||||
this.$refs.tcpFormatParameter.validateXmlDataStruct();
|
||||
}
|
||||
this.$emit('saveApi', this.basisData);
|
||||
if (this.$refs.versionHistory) {
|
||||
|
@ -276,25 +243,9 @@ export default {
|
|||
if (this.basisData.tags instanceof Array) {
|
||||
this.basisData.tags = JSON.stringify(this.basisData.tags);
|
||||
}
|
||||
if (this.basisData.method === 'ESB') {
|
||||
let validataResult = this.$refs.esbDefinition.validateEsbDataStruct(this.request.esbDataStruct);
|
||||
if (!validataResult) {
|
||||
return;
|
||||
}
|
||||
if (this.request.esbDataStruct != null) {
|
||||
this.esbDataStruct = JSON.stringify(this.request.esbDataStruct);
|
||||
this.basisData.esbDataStruct = this.esbDataStruct;
|
||||
}
|
||||
if (this.request.backEsbDataStruct != null) {
|
||||
this.basisData.backEsbDataStruct = JSON.stringify(this.request.backEsbDataStruct);
|
||||
}
|
||||
if (this.request.backScript != null) {
|
||||
this.basisData.backScript = JSON.stringify(this.request.backScript);
|
||||
}
|
||||
} else {
|
||||
if (this.$refs.tcpFormatParameter) {
|
||||
this.$refs.tcpFormatParameter.validateXmlDataStruct();
|
||||
}
|
||||
|
||||
if (this.$refs.tcpFormatParameter) {
|
||||
this.$refs.tcpFormatParameter.validateXmlDataStruct();
|
||||
}
|
||||
this.$emit('runTest', this.basisData);
|
||||
}
|
||||
|
@ -346,11 +297,10 @@ export default {
|
|||
}
|
||||
},
|
||||
getDefaultVersion() {
|
||||
getDefaultVersion(getCurrentProjectID())
|
||||
.then(response => {
|
||||
this.latestVersionId = response.data;
|
||||
this.getVersionHistory();
|
||||
});
|
||||
getDefaultVersion(getCurrentProjectID()).then((response) => {
|
||||
this.latestVersionId = response.data;
|
||||
this.getVersionHistory();
|
||||
});
|
||||
},
|
||||
|
||||
getVersionHistory() {
|
||||
|
@ -362,7 +312,7 @@ export default {
|
|||
}
|
||||
let latestVersionData = response.data.filter((v) => v.versionId === this.latestVersionId);
|
||||
if (latestVersionData.length > 0) {
|
||||
this.hasLatest = false
|
||||
this.hasLatest = false;
|
||||
} else {
|
||||
this.hasLatest = true;
|
||||
}
|
||||
|
@ -558,8 +508,8 @@ export default {
|
|||
projectId: getCurrentProjectID(),
|
||||
type: 'API',
|
||||
versionId: row.id,
|
||||
resourceId: this.basisData.id
|
||||
}
|
||||
resourceId: this.basisData.id,
|
||||
};
|
||||
setLatestVersionById(param).then(() => {
|
||||
this.$success(this.$t('commons.modify_success'));
|
||||
this.checkout(row);
|
||||
|
|
|
@ -47,19 +47,6 @@
|
|||
|
||||
<ms-tcp-format-parameters :show-script="false" :request="oldRequest" ref="tcpFormatParameter" />
|
||||
</div>
|
||||
<div v-else-if="oldApiProtocol === 'ESB'">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<mx-esb-definition
|
||||
v-xpack
|
||||
:show-script="false"
|
||||
:is-read-only="true"
|
||||
:request="oldRequest"
|
||||
ref="esbDefinition" />
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<mx-esb-definition-response v-xpack :is-api-component="true" :is-read-only="true" :request="oldRequest" />
|
||||
<!-- <api-response-component :currentProtocol="apiCase.request.protocol" :api-item="apiCase"/>-->
|
||||
</div>
|
||||
|
||||
<ms-form-divider :title="$t('test_track.case.other_info')" />
|
||||
<api-info-container>
|
||||
<el-form :model="oldData" ref="api-form" label-width="100px">
|
||||
|
@ -123,17 +110,6 @@
|
|||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<ms-tcp-format-parameters :show-script="false" :request="request" ref="tcpFormatParameter" />
|
||||
</div>
|
||||
<div v-else-if="apiProtocol == 'ESB'">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<mx-esb-definition
|
||||
v-xpack
|
||||
:show-script="false"
|
||||
:is-read-only="true"
|
||||
:request="request"
|
||||
ref="esbDefinition" />
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<mx-esb-definition-response v-xpack :is-api-component="true" :is-read-only="true" :request="request" />
|
||||
</div>
|
||||
|
||||
<!-- 其他信息-->
|
||||
<ms-form-divider :title="$t('test_track.case.other_info')" />
|
||||
|
@ -191,8 +167,6 @@ export default {
|
|||
TabPaneCount,
|
||||
FormRichTextItem,
|
||||
DependenciesList,
|
||||
MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'),
|
||||
MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'),
|
||||
},
|
||||
props: {
|
||||
oldData: {
|
||||
|
|
|
@ -1,273 +0,0 @@
|
|||
<template>
|
||||
<div class="text-container">
|
||||
<el-tabs v-model="activeName" v-show="isActive">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.response_template')" name="esbData" class="pane">
|
||||
<esb-table
|
||||
:table-data="request.backEsbDataStruct"
|
||||
:show-options-button="showOptionsButton"
|
||||
@saveTableData="validateEsbDataStruct"
|
||||
ref="esbTable"></esb-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane
|
||||
v-if="isApiComponent === false"
|
||||
:label="$t('api_test.definition.request.response_body')"
|
||||
name="body"
|
||||
class="pane">
|
||||
<ms-code-edit
|
||||
v-if="isMsCodeEditShow"
|
||||
:mode="mode"
|
||||
:read-only="true"
|
||||
:modes="modes"
|
||||
height="200px"
|
||||
:data.sync="response.responseResult.body"
|
||||
ref="codeEdit" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
v-if="isApiComponent === false"
|
||||
:label="$t('api_test.definition.request.console')"
|
||||
name="console"
|
||||
class="pane">
|
||||
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="response.responseResult.console" height="200px" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
v-if="isApiComponent === false"
|
||||
:label="$t('api_report.assertions')"
|
||||
name="assertions"
|
||||
class="pane assertions">
|
||||
<ms-assertion-results :assertions="response.responseResult.assertions" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
v-if="isApiComponent === false"
|
||||
:label="$t('api_test.request.extract.label')"
|
||||
name="label"
|
||||
class="pane">
|
||||
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="response.responseResult.vars" height="200px" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
v-if="isApiComponent === false"
|
||||
:label="$t('api_report.request_body')"
|
||||
name="request_body"
|
||||
class="pane">
|
||||
<ms-code-edit :mode="'text'" :read-only="true" :data.sync="reqMessages" height="200px" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane v-if="isApiComponent === true" :label="$t('api_test.definition.request.post_script')" name="script">
|
||||
<jsr233-processor-content
|
||||
:jsr223-processor="request.backScript"
|
||||
:is-pre-processor="false"
|
||||
:is-read-only="false" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsAssertionResults from '@/business/definition/components/response/AssertionResults';
|
||||
import MsCodeEdit from '@/business/definition/components/MsCodeEdit';
|
||||
import MsDropdown from '@/business/commons/MsDropdown';
|
||||
import { BODY_FORMAT } from '@/business/definition/model/ApiTestModel';
|
||||
import MsSqlResultTable from '@/business/definition/components/response/SqlResultTable';
|
||||
import EsbTable from './EsbTable';
|
||||
import Jsr233ProcessorContent from '@/business/automation/scenario/common/Jsr233ProcessorContent';
|
||||
import { createComponent } from '@/business/definition/components/jmeter/components';
|
||||
|
||||
export default {
|
||||
name: 'EsbResponseResult',
|
||||
|
||||
components: {
|
||||
EsbTable,
|
||||
MsDropdown,
|
||||
MsCodeEdit,
|
||||
MsAssertionResults,
|
||||
MsSqlResultTable,
|
||||
Jsr233ProcessorContent,
|
||||
},
|
||||
|
||||
props: {
|
||||
response: Object,
|
||||
isApiComponent: Boolean,
|
||||
showOptionsButton: Boolean,
|
||||
request: {},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
isActive: true,
|
||||
activeName: 'body',
|
||||
modes: ['text', 'json', 'xml', 'html'],
|
||||
sqlModes: ['text', 'table'],
|
||||
mode: BODY_FORMAT.TEXT,
|
||||
isMsCodeEditShow: true,
|
||||
reqMessages: '',
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
response() {
|
||||
this.setBodyType();
|
||||
this.setReqMessage();
|
||||
},
|
||||
},
|
||||
created() {
|
||||
if (this.isApiComponent) {
|
||||
this.activeName = 'esbData';
|
||||
}
|
||||
if (this.response == null) {
|
||||
this.response = {};
|
||||
}
|
||||
if (this.request.backScript == null) {
|
||||
this.request.backScript = createComponent('JSR223PostProcessor');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
validateEsbDataStruct(esbDataStruct) {
|
||||
this.refreshEsbDataStruct(esbDataStruct);
|
||||
let result = this.checkEsbDataStructData(esbDataStruct);
|
||||
return result;
|
||||
},
|
||||
refreshEsbDataStruct(esbDataStruct) {
|
||||
if (esbDataStruct && esbDataStruct.length > 0) {
|
||||
esbDataStruct.forEach((row) => {
|
||||
row.status = '';
|
||||
if (row.children == null || row.children.length === 0) {
|
||||
row.children = [];
|
||||
} else if (row.children.length > 0) {
|
||||
this.refreshEsbDataStruct(row.children);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
checkEsbDataStructData(esbDataStruct) {
|
||||
let allCheckResult = true;
|
||||
if (esbDataStruct && esbDataStruct.length > 0) {
|
||||
for (let i = 0; i < esbDataStruct.length; i++) {
|
||||
let row = esbDataStruct[i];
|
||||
allCheckResult = this.$refs.esbTable.validateRowData(row);
|
||||
if (allCheckResult) {
|
||||
if (row.children != null && row.children.length > 0) {
|
||||
allCheckResult = this.checkEsbDataStructData(row.children);
|
||||
if (!allCheckResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return allCheckResult;
|
||||
},
|
||||
modeChange(mode) {
|
||||
this.mode = mode;
|
||||
},
|
||||
sqlModeChange(mode) {
|
||||
this.mode = mode;
|
||||
},
|
||||
setBodyType() {
|
||||
if (!this.response.responseResult || !this.response.responseResult.headers) {
|
||||
return;
|
||||
}
|
||||
if (this.response.responseResult.headers.indexOf('Content-Type: application/json') > 0) {
|
||||
this.mode = BODY_FORMAT.JSON;
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.modeDropdown) {
|
||||
this.$refs.modeDropdown.handleCommand(BODY_FORMAT.JSON);
|
||||
this.msCodeReload();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
msCodeReload() {
|
||||
this.isMsCodeEditShow = false;
|
||||
this.$nextTick(() => {
|
||||
this.isMsCodeEditShow = true;
|
||||
});
|
||||
},
|
||||
setReqMessage() {
|
||||
if (this.response) {
|
||||
if (!this.response.url) {
|
||||
this.response.url = '';
|
||||
}
|
||||
if (!this.response.headers) {
|
||||
this.response.headers = '';
|
||||
}
|
||||
if (!this.response.cookies) {
|
||||
this.response.cookies = '';
|
||||
}
|
||||
if (!this.response.body) {
|
||||
this.response.body = '';
|
||||
}
|
||||
if (!this.response.responseResult) {
|
||||
this.response.responseResult = {};
|
||||
}
|
||||
if (!this.response.responseResult.vars) {
|
||||
this.response.responseResult.vars = '';
|
||||
}
|
||||
this.reqMessages =
|
||||
this.$t('api_test.request.address') +
|
||||
':\n' +
|
||||
this.response.url +
|
||||
'\n' +
|
||||
this.$t('api_test.scenario.headers') +
|
||||
':\n' +
|
||||
this.response.headers +
|
||||
'\n' +
|
||||
'Cookie :' +
|
||||
this.response.cookies +
|
||||
'\n' +
|
||||
'Body:' +
|
||||
'\n' +
|
||||
this.response.body;
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.setBodyType();
|
||||
this.setReqMessage();
|
||||
},
|
||||
computed: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.text-container .icon {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.text-container .collapse {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.text-container .collapse:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.text-container .icon.is-active {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.text-container .pane {
|
||||
/*background-color: #F5F5F5;*/
|
||||
padding: 0 10px;
|
||||
/*height: 250px;*/
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.text-container .pane.cookie {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
.ms-div {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
|
@ -1,330 +0,0 @@
|
|||
<template>
|
||||
<div class="ms-border">
|
||||
<el-table
|
||||
:data="tableData"
|
||||
@cell-dblclick="editRow"
|
||||
row-key="uuid"
|
||||
v-loading="loading"
|
||||
:expand-row-keys="expands"
|
||||
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
|
||||
<el-table-column prop="esbName" :label="$t('api_test.definition.request.esb_table.name')" width="230">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-if="scope.row.status" v-model="scope.row.name" style="width: 140px"></el-input>
|
||||
<span v-else>{{ scope.row.name }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" :label="$t('api_test.definition.request.esb_table.type')" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-if="scope.row.status" v-model="scope.row.type" :placeholder="$t('commons.please_select')">
|
||||
<el-option v-for="item in typeSelectOptions" :key="item.value" :label="item.value" :value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<span v-else>{{ scope.row.type }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="length" :label="$t('api_test.definition.request.esb_table.length')" width="80">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-if="scope.row.status" v-model="scope.row.contentType"></el-input>
|
||||
<span v-else>{{ scope.row.contentType }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" :label="$t('api_test.definition.request.esb_table.desc')" min-width="200">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-if="scope.row.status" v-model="scope.row.description"></el-input>
|
||||
<span v-else>{{ scope.row.description }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="value" :label="$t('api_test.definition.request.esb_table.value')" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-if="scope.row.status" v-model="scope.row.value"></el-input>
|
||||
<span v-else>{{ scope.row.value }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="showOptionsButton" :label="$t('commons.operating')" width="140" fixed="right">
|
||||
<template v-slot:default="scope">
|
||||
<span>
|
||||
<el-button
|
||||
size="mini"
|
||||
p="$t('commons.next_level')"
|
||||
icon="el-icon-plus"
|
||||
type="primary"
|
||||
circle
|
||||
@click="nextRow(scope.row)"
|
||||
class="ht-btn-confirm" />
|
||||
<el-button
|
||||
size="mini"
|
||||
p="$t('commons.copy')"
|
||||
icon="el-icon-copy-document"
|
||||
type="primary"
|
||||
circle
|
||||
@click="copyDataStructConfirm(scope.row)"
|
||||
class="ht-btn-confirm" />
|
||||
<el-button
|
||||
size="mini"
|
||||
p="$t('commons.remove')"
|
||||
icon="el-icon-close"
|
||||
circle
|
||||
@click="remove(scope.row)"
|
||||
class="ht-btn-remove" />
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-if="showOptionsButton">
|
||||
<el-button class="ht-btn-add" size="mini" p="$t('commons.add')" icon="el-icon-circle-plus-outline" @click="add">
|
||||
{{ $t('commons.add') }}
|
||||
</el-button>
|
||||
<el-button
|
||||
class="ht-btn-add"
|
||||
size="mini"
|
||||
p="$t('commons.add')"
|
||||
icon="el-icon-circle-plus-outline"
|
||||
@click="saveTableData"
|
||||
>{{ $t('commons.save') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'EsbTable',
|
||||
components: {},
|
||||
props: {
|
||||
tableData: Array,
|
||||
showOptionsButton: Boolean,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
expands: [],
|
||||
typeSelectOptions: [
|
||||
{ value: 'object', label: '[object]' },
|
||||
{ value: 'string', label: '[string]' },
|
||||
{ value: 'array', label: '[array]' },
|
||||
],
|
||||
requiredSelectOptions: [
|
||||
{ value: true, label: '必填' },
|
||||
{ value: false, label: '非必填' },
|
||||
],
|
||||
tableExpandRowKayArray: ['name', 'systemName'],
|
||||
};
|
||||
},
|
||||
created() {
|
||||
if (this.tableData && this.tableData.length > 0) {
|
||||
this.tableData.forEach((row) => {
|
||||
if (row.name == null || row.name === '') {
|
||||
this.remove(row);
|
||||
}
|
||||
});
|
||||
this.expands.push(this.tableData[0].uuid);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
saveTableData: function () {
|
||||
this.$emit('saveTableData', this.tableData);
|
||||
},
|
||||
remove: function (row) {
|
||||
this.removeTableRow(row);
|
||||
},
|
||||
add: function (r) {
|
||||
let row = this.getNewRow(null);
|
||||
this.pushTableData(row);
|
||||
},
|
||||
nextRow: function (row) {
|
||||
//首先保存当前行内容
|
||||
let confirmRowFlag = this.confirm(row);
|
||||
if (confirmRowFlag) {
|
||||
let nextRow = this.getNewRow(null);
|
||||
this.pushTableData(nextRow, row.uuid);
|
||||
}
|
||||
},
|
||||
//复制当前数据结构
|
||||
copyDataStructConfirm: function (row) {
|
||||
this.$alert(this.$t('api_test.definition.request.esb_copy_confirm') + ' ?', '', {
|
||||
confirmButtonText: this.$t('commons.confirm'),
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
this.copyDataStruct(row);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
copyDataStruct: function (row) {
|
||||
let parentRow = this.selectParentRow(this.tableData, row.uuid);
|
||||
let newRow = this.createNewId(row);
|
||||
if (parentRow != null) {
|
||||
if (parentRow.children == null) {
|
||||
parentRow.children = [];
|
||||
}
|
||||
parentRow.children.push(newRow);
|
||||
} else {
|
||||
this.tableData.push(newRow);
|
||||
}
|
||||
},
|
||||
createNewId(row) {
|
||||
let newRow = this.getNewRow(row);
|
||||
if (row.children != null && row.children.length > 0) {
|
||||
row.children.forEach((child) => {
|
||||
let newChild = this.createNewId(child);
|
||||
newRow.children.push(newChild);
|
||||
});
|
||||
}
|
||||
return newRow;
|
||||
},
|
||||
selectParentRow(esbDataStruct, rowId) {
|
||||
let returnRow = null;
|
||||
if (esbDataStruct == null || esbDataStruct.length === 0) {
|
||||
return returnRow;
|
||||
}
|
||||
esbDataStruct.forEach((esbData) => {
|
||||
if (esbData.children != null && esbData.children.length > 0) {
|
||||
esbData.children.forEach((child) => {
|
||||
if (child.uuid === rowId) {
|
||||
returnRow = esbData;
|
||||
return returnRow;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (returnRow == null) {
|
||||
if (esbData.children != null && esbData.children.length > 0) {
|
||||
returnRow = this.selectParentRow(esbData.children, rowId);
|
||||
if (returnRow != null) {
|
||||
return returnRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return returnRow;
|
||||
},
|
||||
confirm: function (row) {
|
||||
this.validateRowData(row) ? (row.status = '') : row.status;
|
||||
if (row.status === '') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getNewRow(param) {
|
||||
if (param == null) {
|
||||
let row = {
|
||||
name: '',
|
||||
systemName: '',
|
||||
status: 'edit',
|
||||
type: '[object]',
|
||||
contentType: '',
|
||||
required: false,
|
||||
description: '',
|
||||
uuid: this.uuid(),
|
||||
children: [],
|
||||
};
|
||||
return row;
|
||||
} else {
|
||||
let row = {
|
||||
name: param.name,
|
||||
systemName: param.systemName,
|
||||
status: '',
|
||||
type: param.type,
|
||||
contentType: param.contentType,
|
||||
required: param.required,
|
||||
description: param.description,
|
||||
uuid: this.uuid(),
|
||||
children: [],
|
||||
};
|
||||
return row;
|
||||
}
|
||||
},
|
||||
validateRowData(row) {
|
||||
if (row.name == null || row.name === '') {
|
||||
// this.$warning(this.$t('load_test.input_ip'));
|
||||
this.$warning('ESB参数名' + '不能为空,且不能包含英文小数点[.]');
|
||||
return false;
|
||||
} else if (row.name.indexOf('.') > 0) {
|
||||
this.$warning('ESB参数名[' + row.name + ']不合法,不能包含英文小数点"."!');
|
||||
return false;
|
||||
} else if (row.type == null || row.type === '') {
|
||||
this.$warning('类型' + '不能为空!');
|
||||
return false;
|
||||
// }else if(row.required == null || row.required == '' ){
|
||||
// }else if(row.required != false && row.required != true){
|
||||
// this.$warning("是否必填"+"不能为空!");
|
||||
// return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
editRow: function (row) {
|
||||
row.status = 'edit';
|
||||
},
|
||||
uuid: function () {
|
||||
return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
|
||||
},
|
||||
pushTableData: function (dataRow, rowId) {
|
||||
if (rowId === '' || rowId == null) {
|
||||
if (this.tableData == null) {
|
||||
this.tableData = [];
|
||||
}
|
||||
this.tableData.push(dataRow);
|
||||
} else {
|
||||
this.appendDataWithDeepForeach(this.tableData, rowId, dataRow);
|
||||
}
|
||||
},
|
||||
appendDataWithDeepForeach(data, rowId, appendData) {
|
||||
data.forEach((row) => {
|
||||
if (row.uuid === rowId) {
|
||||
if (row.children == null) {
|
||||
row.children = [];
|
||||
}
|
||||
row.children.push(appendData);
|
||||
} else if (row.children.length > 0) {
|
||||
let appendResult = this.appendDataWithDeepForeach(row.children, rowId, appendData);
|
||||
if (appendResult) {
|
||||
return appendResult;
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
removeTableRow: function (row) {
|
||||
this.removeFromEsbDataStruct(this.tableData, row);
|
||||
},
|
||||
removeFromEsbDataStruct(esbDataStruct, row) {
|
||||
if (esbDataStruct == null || esbDataStruct.length === 0) {
|
||||
return;
|
||||
}
|
||||
let rowIndex = esbDataStruct.indexOf(row);
|
||||
if (rowIndex >= 0) {
|
||||
esbDataStruct.splice(rowIndex, 1);
|
||||
} else {
|
||||
esbDataStruct.forEach((esbData) => {
|
||||
if (esbData.children != null && esbData.children.length > 0) {
|
||||
this.removeFromEsbDataStruct(esbData.children, row);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ht-btn-remove {
|
||||
color: white;
|
||||
background-color: #dcdfe6;
|
||||
}
|
||||
|
||||
.ht-btn-confirm {
|
||||
color: white;
|
||||
/*background-color: #1483F6;*/
|
||||
}
|
||||
|
||||
.ht-btn-add {
|
||||
border: 0px;
|
||||
margin-top: 10px;
|
||||
color: #783887;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.ht-tb {
|
||||
background-color: white;
|
||||
border: 0px;
|
||||
}
|
||||
</style>
|
|
@ -1,390 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col :span="spanNum" style="padding-bottom: 20px">
|
||||
<div style="border: 1px #dcdfe6 solid; height: 100%; border-radius: 4px; width: 100%">
|
||||
<el-form
|
||||
class="tcp"
|
||||
:model="request"
|
||||
:rules="rules"
|
||||
ref="request"
|
||||
:disabled="isReadOnly"
|
||||
style="margin: 20px">
|
||||
<el-tabs v-model="activeName" class="request-tabs" @tab-click="tabClick">
|
||||
<!--query 参数-->
|
||||
<el-tab-pane name="parameters" v-if="isBodyShow">
|
||||
<template v-slot:label>
|
||||
{{ $t('api_test.definition.request.req_param') }}
|
||||
<ms-instructions-icon :content="$t('api_test.definition.request.esb_title')" />
|
||||
</template>
|
||||
<esb-table
|
||||
:table-data="request.esbDataStruct"
|
||||
:show-options-button="true"
|
||||
@saveTableData="validateEsbDataStruct"
|
||||
ref="esbTable"></esb-table>
|
||||
</el-tab-pane>
|
||||
<!--报文模版-->
|
||||
<el-tab-pane :label="$t('api_test.definition.request.message_template')" name="request">
|
||||
<div class="send-request">
|
||||
<ms-code-edit
|
||||
mode="text"
|
||||
:read-only="isReadOnly"
|
||||
:data.sync="request.request"
|
||||
:modes="['text', 'json', 'xml', 'html']"
|
||||
theme="eclipse" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<!--其他设置-->
|
||||
<el-tab-pane :label="$t('api_test.definition.request.other_config')" name="other" class="other-config">
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="TCPClient" prop="classname">
|
||||
<el-select v-model="request.classname" style="width: 100%" size="small">
|
||||
<el-option v-for="c in classes" :key="c" :label="c" :value="c" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout">
|
||||
<el-input-number v-model="request.ctimeout" controls-position="right" :min="0" size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout">
|
||||
<el-input-number v-model="request.timeout" controls-position="right" :min="0" size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
|
||||
<el-input v-model="request.soLinger" size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
|
||||
<el-input v-model="request.eolByte" size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.username')" prop="username">
|
||||
<el-input v-model="request.username" maxlength="100" show-word-limit size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.password')" prop="password">
|
||||
<el-input
|
||||
v-model="request.password"
|
||||
maxlength="30"
|
||||
show-word-limit
|
||||
show-password
|
||||
autocomplete="new-password"
|
||||
size="small" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="10" style="margin-left: 30px">
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.re_use_connection')">
|
||||
<el-checkbox v-model="request.reUseConnection" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.close_connection')">
|
||||
<el-checkbox v-model="request.closeConnection" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item :label="$t('api_test.request.tcp.no_delay')">
|
||||
<el-checkbox v-model="request.nodelay" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="Connect encoding">
|
||||
<el-select v-model="request.connectEncoding" style="width: 100px" size="small">
|
||||
<el-option
|
||||
v-for="item in connectEncodingArr"
|
||||
:key="item.key"
|
||||
:label="item.value"
|
||||
:value="item.key" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- 脚本步骤/断言步骤 -->
|
||||
<el-tab-pane :label="$t('api_test.definition.request.pre_operation')" name="preOperate" v-if="showScript">
|
||||
<span class="item-tabs" effect="dark" placement="top-start" slot="label">
|
||||
{{ $t('api_test.definition.request.pre_operation') }}
|
||||
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.preSize > 0">
|
||||
<div class="el-step__icon-inner">{{ request.preSize }}</div>
|
||||
</div>
|
||||
</span>
|
||||
<ms-jmx-step
|
||||
:request="request"
|
||||
:apiId="request.id"
|
||||
:response="response"
|
||||
:tab-type="'pre'"
|
||||
ref="preStep" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.post_operation')"
|
||||
name="postOperate"
|
||||
v-if="showScript">
|
||||
<span class="item-tabs" effect="dark" placement="top-start" slot="label">
|
||||
{{ $t('api_test.definition.request.post_operation') }}
|
||||
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.postSize > 0">
|
||||
<div class="el-step__icon-inner">
|
||||
{{ request.postSize }}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<ms-jmx-step
|
||||
:request="request"
|
||||
:apiId="request.id"
|
||||
:response="response"
|
||||
:tab-type="'post'"
|
||||
ref="postStep"
|
||||
protocol="TCP" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.assertions_rule')"
|
||||
name="assertionsRule"
|
||||
v-if="showScript">
|
||||
<span class="item-tabs" effect="dark" placement="top-start" slot="label">
|
||||
{{ $t('api_test.definition.request.assertions_rule') }}
|
||||
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.ruleSize > 0">
|
||||
<div class="el-step__icon-inner">
|
||||
{{ request.ruleSize }}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
<ms-jmx-step
|
||||
:request="request"
|
||||
:apiId="request.id"
|
||||
:response="response"
|
||||
@reload="reloadBody"
|
||||
:tab-type="'assertionsRule'"
|
||||
ref="assertionsRule"
|
||||
protocol="TCP" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TCPSampler from '@/business/definition/components/jmeter/components/sampler/tcp-sampler';
|
||||
import MsCodeEdit from 'metersphere-frontend/src/components/MsCodeEdit';
|
||||
import Jsr233Processor from '@/business/automation/scenario/component/Jsr233Processor';
|
||||
import Jsr233ProcessorContent from '@/business/automation/scenario/common/Jsr233ProcessorContent';
|
||||
import ApiDefinitionStepButton from '@/business/definition/components/request/components/ApiDefinitionStepButton';
|
||||
import MsInstructionsIcon from 'metersphere-frontend/src/components/MsInstructionsIcon';
|
||||
import EsbTable from './EsbTable';
|
||||
import MsJmxStep from '@/business/definition/components/step/JmxStep';
|
||||
import { stepCompute, hisDataProcessing } from '@/business/definition/api-definition';
|
||||
import { operationConfirm } from 'metersphere-frontend/src/utils';
|
||||
|
||||
export default {
|
||||
name: 'MxEsbDefinition',
|
||||
components: {
|
||||
MsCodeEdit,
|
||||
Jsr233Processor,
|
||||
Jsr233ProcessorContent,
|
||||
MsInstructionsIcon,
|
||||
ApiDefinitionStepButton,
|
||||
EsbTable,
|
||||
MsJmxStep,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
spanNum: 21,
|
||||
activeName: 'parameters',
|
||||
isReloadData: false,
|
||||
isBodyShow: true,
|
||||
classes: TCPSampler.CLASSES,
|
||||
connectEncodingArr: [
|
||||
{
|
||||
key: 'UTF-8',
|
||||
value: 'UTF-8',
|
||||
},
|
||||
{
|
||||
key: 'GBK',
|
||||
value: 'GBK',
|
||||
},
|
||||
],
|
||||
rules: {
|
||||
classname: [{ required: true, message: '请选择TCPClient', trigger: 'change' }],
|
||||
server: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$t('api_test.request.tcp.server_cannot_be_empty'),
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
port: [
|
||||
{
|
||||
required: true,
|
||||
message: this.$t('commons.port_cannot_be_empty'),
|
||||
trigger: 'change',
|
||||
},
|
||||
],
|
||||
},
|
||||
previewReadOnly: true,
|
||||
};
|
||||
},
|
||||
props: {
|
||||
request: {},
|
||||
basisData: {},
|
||||
response: {},
|
||||
moduleOptions: Array,
|
||||
esbDataStruct: String,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
showScript: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
showPreScript: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
referenced: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'request.hashTree': {
|
||||
handler(v) {
|
||||
this.initStepSize(this.request.hashTree);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.spanNum = 24;
|
||||
if (this.request.esbDataStruct) {
|
||||
this.refreshEsbDataStruct(this.request.esbDataStruct);
|
||||
} else {
|
||||
this.request.esbDataStruct = [];
|
||||
}
|
||||
if (this.request.tcpPreProcessor && this.request.tcpPreProcessor.script) {
|
||||
this.request.hashTree.push(this.request.tcpPreProcessor);
|
||||
this.request.tcpPreProcessor = undefined;
|
||||
}
|
||||
if (!this.request.connectEncoding) {
|
||||
this.request.connectEncoding = 'UTF-8';
|
||||
}
|
||||
if (this.request.hashTree) {
|
||||
this.initStepSize(this.request.hashTree);
|
||||
this.historicalDataProcessing(this.request.hashTree);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
tabClick() {
|
||||
if (this.activeName === 'preOperate') {
|
||||
this.$refs.preStep.filter();
|
||||
}
|
||||
if (this.activeName === 'postOperate') {
|
||||
this.$refs.postStep.filter();
|
||||
}
|
||||
if (this.activeName === 'assertionsRule') {
|
||||
this.$refs.assertionsRule.filter();
|
||||
}
|
||||
},
|
||||
historicalDataProcessing(array) {
|
||||
hisDataProcessing(array, this.request);
|
||||
},
|
||||
initStepSize(array) {
|
||||
stepCompute(array, this.request);
|
||||
this.reloadBody();
|
||||
},
|
||||
reloadBody() {
|
||||
// 解决修改请求头后 body 显示错位
|
||||
this.isBodyShow = false;
|
||||
this.$nextTick(() => {
|
||||
this.isBodyShow = true;
|
||||
});
|
||||
},
|
||||
refreshEsbDataStruct(esbDataStruct) {
|
||||
if (esbDataStruct && esbDataStruct.length > 0) {
|
||||
esbDataStruct.forEach((row) => {
|
||||
row.status = '';
|
||||
if (row.children == null || row.children.length === 0) {
|
||||
row.children = [];
|
||||
} else if (row.children.length > 0) {
|
||||
this.refreshEsbDataStruct(row.children);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
checkEsbDataStructData(esbDataStruct) {
|
||||
let allCheckResult = true;
|
||||
if (esbDataStruct && esbDataStruct.length > 0) {
|
||||
for (let i = 0; i < esbDataStruct.length; i++) {
|
||||
let row = esbDataStruct[i];
|
||||
allCheckResult = this.$refs.esbTable.validateRowData(row);
|
||||
if (allCheckResult) {
|
||||
if (row.children != null && row.children.length > 0) {
|
||||
allCheckResult = this.checkEsbDataStructData(row.children);
|
||||
if (!allCheckResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return allCheckResult;
|
||||
},
|
||||
validateEsbDataStruct(esbDataStruct) {
|
||||
this.refreshEsbDataStruct(esbDataStruct);
|
||||
const result = this.checkEsbDataStructData(esbDataStruct);
|
||||
return result;
|
||||
},
|
||||
validate() {
|
||||
let validateResult = this.validateEsbDataStruct(this.request.esbDataStruct);
|
||||
if (validateResult) {
|
||||
this.$emit('callback');
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tip {
|
||||
padding: 3px 5px;
|
||||
font-size: 16px;
|
||||
border-radius: 4px;
|
||||
border-left: 4px solid #783887;
|
||||
margin: 0px 20px 0px;
|
||||
}
|
||||
|
||||
.ms-header {
|
||||
background: #783887;
|
||||
color: white;
|
||||
height: 18px;
|
||||
border-radius: 42%;
|
||||
}
|
||||
|
||||
.send-request {
|
||||
padding: 0px 0;
|
||||
height: 300px;
|
||||
border: 1px #dcdfe6 solid;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
|
@ -1,156 +0,0 @@
|
|||
<template>
|
||||
<el-row>
|
||||
<el-col :span="spanNum">
|
||||
<div style="border: 1px #dcdfe6 solid; height: 100%; border-radius: 4px; width: 100%">
|
||||
<el-form class="tcp" :model="request" ref="request" :disabled="isReadOnly" style="margin: 20px">
|
||||
<el-card v-if="showHeader" class="api-component">
|
||||
<div class="header" @click="active">
|
||||
<i class="icon el-icon-arrow-right" :class="{ 'is-active': isActive }" />
|
||||
<ms-request-metric :response="response" />
|
||||
</div>
|
||||
|
||||
<el-collapse-transition>
|
||||
<div v-if="isActive">
|
||||
<el-divider></el-divider>
|
||||
<esb-response-result
|
||||
:show-options-button="showOptionsButton"
|
||||
:is-api-component="false"
|
||||
:show-metric="false"
|
||||
:response="response"
|
||||
:request="request" />
|
||||
</div>
|
||||
</el-collapse-transition>
|
||||
</el-card>
|
||||
<esb-response-result
|
||||
v-else
|
||||
:show-options-button="showOptionsButton"
|
||||
:request="request"
|
||||
@refreshEsbDataStruct="refreshEsbDataStruct"
|
||||
:is-api-component="isApiComponent"
|
||||
:show-metric="false"
|
||||
:response="response" />
|
||||
</el-form>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getApiReportDetail } from '@/api/definition-report';
|
||||
import ApiBaseComponent from '@/business/automation/scenario/common/ApiBaseComponent';
|
||||
import MsRequestResultTail from '@/business/definition/components/response/RequestResultTail';
|
||||
import ElCollapseTransition from 'element-ui/src/transitions/collapse-transition';
|
||||
import MsRequestMetric from '@/business/definition/components/response/RequestMetric';
|
||||
import EsbResponseResult from './EsbResponseResult';
|
||||
|
||||
export default {
|
||||
name: 'MxEsbDefinitionResponse',
|
||||
components: {
|
||||
ElCollapseTransition,
|
||||
MsRequestResultTail,
|
||||
ApiBaseComponent,
|
||||
MsRequestMetric,
|
||||
EsbResponseResult,
|
||||
},
|
||||
props: {
|
||||
apiItem: {},
|
||||
result: {},
|
||||
showHeader: Boolean,
|
||||
showOptionsButton: Boolean,
|
||||
isApiComponent: Boolean,
|
||||
responseData: Object,
|
||||
request: {},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
spanNum: 21,
|
||||
isActive: false,
|
||||
isReadOnly: false,
|
||||
response: { responseResult: {} },
|
||||
};
|
||||
},
|
||||
created() {
|
||||
if (!this.referenced && this.showScript) {
|
||||
this.spanNum = 21;
|
||||
} else {
|
||||
this.spanNum = 24;
|
||||
}
|
||||
if (!this.result) {
|
||||
if (!this.isApiComponent) {
|
||||
this.getExecResult();
|
||||
}
|
||||
} else {
|
||||
this.response = this.result;
|
||||
}
|
||||
|
||||
if (this.request.backEsbDataStruct) {
|
||||
this.refreshEsbDataStruct(this.request.backEsbDataStruct);
|
||||
} else {
|
||||
this.request.backEsbDataStruct = [];
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
result() {
|
||||
this.response = this.result;
|
||||
},
|
||||
responseData() {
|
||||
this.response = this.responseData;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getExecResult() {
|
||||
// 执行结果信息
|
||||
if (this.apiItem) {
|
||||
getApiReportDetail(this.apiItem.id).then((response) => {
|
||||
if (response.data) {
|
||||
let data = JSON.parse(response.data.content);
|
||||
this.response = data;
|
||||
this.$set(this.apiItem, 'responseData', data);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
active() {
|
||||
this.isActive = !this.isActive;
|
||||
},
|
||||
refreshEsbDataStruct(backEsbDataStruct) {
|
||||
if (backEsbDataStruct && backEsbDataStruct.length > 0) {
|
||||
backEsbDataStruct.forEach((row) => {
|
||||
row.status = '';
|
||||
if (row.children == null || row.children.length === 0) {
|
||||
row.children = [];
|
||||
} else if (row.children.length > 0) {
|
||||
this.refreshEsbDataStruct(row.children);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
:deep(.el-card__body) {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.icon.is-active {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.el-icon-arrow-right {
|
||||
float: left;
|
||||
display: block;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.metric-container {
|
||||
margin-left: 25px;
|
||||
}
|
||||
</style>
|
|
@ -39,7 +39,7 @@
|
|||
clearable
|
||||
checkStrictly />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!isScenarioModel && showImportModel" :label="$t('commons.import_mode')" prop="modeId">
|
||||
<el-form-item v-if="!isScenarioModel" :label="$t('commons.import_mode')" prop="modeId">
|
||||
<el-select size="small" v-model="formData.modeId" clearable style="width: 100%">
|
||||
<el-option v-for="item in modeOptions" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
|
@ -78,11 +78,6 @@
|
|||
<el-option v-for="item in versionOptions" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="showTemplate">
|
||||
<el-button type="small" @click="downloadTemplate">
|
||||
{{ $t('test_track.case.import.download_template') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="isSwagger2">
|
||||
<el-switch v-model="swaggerUrlEnable" :active-text="$t('api_test.api_import.swagger_url_import')">
|
||||
</el-switch>
|
||||
|
@ -187,7 +182,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { exportEsbTemp } from '@/api/definition';
|
||||
import { getProjectVersions, versionEnableByProjectId } from '@/api/xpack';
|
||||
import { importScenario } from '@/api/scenario';
|
||||
import MsDialogFooter from 'metersphere-frontend/src/components/MsDialogFooter';
|
||||
|
@ -274,13 +268,6 @@ export default {
|
|||
exportTip: this.$t('api_test.api_import.har_export_tip'),
|
||||
suffixes: new Set(['har']),
|
||||
},
|
||||
esbPlanform: {
|
||||
name: 'ESB',
|
||||
value: 'ESB',
|
||||
tip: this.$t('api_test.api_import.esb_tip'),
|
||||
exportTip: this.$t('api_test.api_import.esb_export_tip'),
|
||||
suffixes: new Set(['xlsx', 'xls']),
|
||||
},
|
||||
jmeterPlatform: {
|
||||
name: 'JMeter',
|
||||
value: 'Jmeter',
|
||||
|
@ -346,16 +333,11 @@ export default {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (this.selectedPlatformValue === 'ESB') {
|
||||
this.formData.modeId = 'fullCoverage';
|
||||
this.$refs.form.clearValidate();
|
||||
}
|
||||
},
|
||||
protocol() {
|
||||
let postmanIndex = this.platforms.indexOf(this.postmanPlanform);
|
||||
let swaggerPlanformIndex = this.platforms.indexOf(this.swaggerPlanform);
|
||||
let harPlanformIndex = this.platforms.indexOf(this.harPlanform);
|
||||
let esbPlanformIndex = this.platforms.indexOf(this.esbPlanform);
|
||||
if (postmanIndex >= 0) {
|
||||
this.platforms.splice(this.platforms.indexOf(this.postmanPlanform), 1);
|
||||
}
|
||||
|
@ -365,13 +347,7 @@ export default {
|
|||
if (harPlanformIndex >= 0) {
|
||||
this.platforms.splice(this.platforms.indexOf(this.harPlanform), 1);
|
||||
}
|
||||
if (esbPlanformIndex >= 0) {
|
||||
this.platforms.splice(this.platforms.indexOf(this.esbPlanform), 1);
|
||||
}
|
||||
if (this.protocol === 'TCP') {
|
||||
if (hasLicense()) {
|
||||
this.platforms.push(this.esbPlanform);
|
||||
}
|
||||
return true;
|
||||
} else if (this.protocol === 'HTTP') {
|
||||
this.platforms.push(this.postmanPlanform);
|
||||
|
@ -385,12 +361,6 @@ export default {
|
|||
isSwagger2() {
|
||||
return this.selectedPlatformValue === 'Swagger2';
|
||||
},
|
||||
showImportModel() {
|
||||
return this.selectedPlatformValue !== 'ESB';
|
||||
},
|
||||
showTemplate() {
|
||||
return this.selectedPlatformValue === 'ESB';
|
||||
},
|
||||
isScenarioModel() {
|
||||
return this.model === 'scenario';
|
||||
},
|
||||
|
@ -438,11 +408,6 @@ export default {
|
|||
handleRemove(file, fileList) {
|
||||
this.formData.file = undefined;
|
||||
},
|
||||
downloadTemplate() {
|
||||
if (this.selectedPlatformValue == 'ESB') {
|
||||
exportEsbTemp('esb-temp');
|
||||
}
|
||||
},
|
||||
uploadValidate(file, fileList) {
|
||||
let suffix = file.name.substring(file.name.lastIndexOf('.') + 1);
|
||||
if (this.selectedPlatform.suffixes && !this.selectedPlatform.suffixes.has(suffix)) {
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
</el-form>
|
||||
|
||||
<!-- TCP 请求参数 -->
|
||||
<div v-if="api.method == 'TCP'" v-loading="loading">
|
||||
<div v-loading="loading">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<ms-tcp-format-parameters
|
||||
:request="api.request"
|
||||
|
@ -48,20 +48,6 @@
|
|||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<ms-request-result-tail :response="responseData" ref="runResult" />
|
||||
</div>
|
||||
<div v-else-if="api.method == 'ESB'" v-loading="loading">
|
||||
<p class="tip">{{ $t('api_test.definition.request.req_param') }}</p>
|
||||
<mx-esb-definition v-xpack :show-script="true" :request="api.request" @callback="runTest" ref="requestForm" />
|
||||
</div>
|
||||
|
||||
<div v-if="api.method == 'ESB'">
|
||||
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
|
||||
<mx-esb-definition-response
|
||||
v-xpack
|
||||
:is-api-component="false"
|
||||
:show-options-button="false"
|
||||
:request="api.request"
|
||||
:response-data="responseData" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 加载用例 -->
|
||||
|
@ -119,8 +105,6 @@ export default {
|
|||
MsRequestResultTail,
|
||||
MsRun,
|
||||
MsTcpFormatParameters,
|
||||
MxEsbDefinition: () => import('@/business/definition/components/esb/MxEsbDefinition'),
|
||||
MxEsbDefinitionResponse: () => import('@/business/definition/components/esb/MxEsbDefinitionResponse'),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -312,10 +296,6 @@ export default {
|
|||
if (this.api.tags instanceof Array) {
|
||||
this.api.tags = JSON.stringify(this.api.tags);
|
||||
}
|
||||
if (this.api.method === 'ESB') {
|
||||
this.api.esbDataStruct = JSON.stringify(this.api.request.esbDataStruct);
|
||||
this.api.backEsbDataStruct = JSON.stringify(this.api.request.backEsbDataStruct);
|
||||
}
|
||||
// 历史数据兼容处理
|
||||
if (this.api.request) {
|
||||
this.api.request.clazzName = TYPE_TO_C.get(this.api.request.type);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
:request="detail"
|
||||
v-if="detail.type === 'HTTPSamplerProxy' || detail.type === 'HTTP'" />
|
||||
<ms-api-tcp-parameters :request="detail" v-if="detail.type === 'TCPSampler'" />
|
||||
<ms-api-tcp-esb :request="detail" v-if="detail.type === 'ESB'" />
|
||||
<ms-api-jdbc-parameters :request="detail" v-if="detail.type === 'JDBCSampler'" />
|
||||
<ms-api-dubbo-parameters :request="detail" v-if="detail.type === 'DubboSampler'" />
|
||||
</div>
|
||||
|
@ -33,7 +32,6 @@ import MsApiHttpRequestParams from './ApiHttpRequestParams';
|
|||
import MsApiTcpParameters from './ApiTcpParameters';
|
||||
import MsApiJdbcParameters from './ApiJdbcParameters';
|
||||
import MsApiDubboParameters from './ApiDubboParameters';
|
||||
import MsApiTcpEsb from './ApiTcpEsb';
|
||||
|
||||
import { getUUID } from 'metersphere-frontend/src/utils';
|
||||
import Convert from '@/business/commons/json-schema/convert/convert';
|
||||
|
@ -45,7 +43,6 @@ export default {
|
|||
MsApiTcpParameters,
|
||||
MsApiJdbcParameters,
|
||||
MsApiDubboParameters,
|
||||
MsApiTcpEsb,
|
||||
},
|
||||
props: {
|
||||
title: String,
|
||||
|
@ -83,8 +80,6 @@ export default {
|
|||
this.formatHttp(diffValue);
|
||||
} else if (diffValue.type === 'TCPSampler') {
|
||||
this.formatTcp(diffValue);
|
||||
} else if (diffValue.type === 'ESB') {
|
||||
this.formatTcpEsb(diffValue);
|
||||
} else if (diffValue.type === 'JDBCSampler') {
|
||||
this.formatJdbc(diffValue);
|
||||
} else if (diffValue.type === 'DubboSampler') {
|
||||
|
@ -227,40 +222,6 @@ export default {
|
|||
this.detail.headerId = getUUID();
|
||||
}
|
||||
},
|
||||
formatTcpEsb(diffValue) {
|
||||
if (!this.detail.body) {
|
||||
this.detail.body = {};
|
||||
}
|
||||
if (diffValue.query1 || diffValue.query2) {
|
||||
this.detail.query1 = diffValue.query1;
|
||||
this.detail.query2 = diffValue.query2;
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
if (diffValue.request1 || diffValue.request2) {
|
||||
this.detail.request1 = diffValue.request1;
|
||||
this.detail.request2 = diffValue.request2;
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
if (diffValue.script1 || diffValue.script2) {
|
||||
this.detail.script1 = diffValue.script1;
|
||||
this.detail.script2 = diffValue.script2;
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
if (diffValue.otherConfig) {
|
||||
this.detail.otherConfig = JSON.parse(diffValue.otherConfig);
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
if (diffValue.backEsbDataStruct1 || diffValue.backEsbDataStruct2) {
|
||||
this.detail.backEsbDataStruct1 = diffValue.backEsbDataStruct1;
|
||||
this.detail.backEsbDataStruct2 = diffValue.backEsbDataStruct2;
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
if (diffValue.backScript1 || diffValue.backScript2) {
|
||||
this.detail.backScript1 = diffValue.backScript1;
|
||||
this.detail.backScript2 = diffValue.backScript2;
|
||||
this.detail.headerId = getUUID();
|
||||
}
|
||||
},
|
||||
formatJdbc(diffValue) {
|
||||
if (diffValue.base) {
|
||||
let parameters = JSON.parse(diffValue.base);
|
||||
|
|
|
@ -1,247 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<div style="border: 1px #dcdfe6 solid; height: 100%; border-radius: 4px; width: 98%">
|
||||
<el-form class="tcp" :model="request" ref="request" :disabled="isReadOnly" style="margin: 20px">
|
||||
<el-tabs v-model="activeName" class="request-tabs">
|
||||
<el-tab-pane
|
||||
name="parameters"
|
||||
:label="$t('api_test.definition.request.req_param')"
|
||||
v-if="request.query1 || request.query2">
|
||||
<pre v-html="getDiff(request.query2, request.query1)"></pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<!--报文模版-->
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.message_template')"
|
||||
name="request"
|
||||
v-if="request.request1 || request.request2">
|
||||
<pre v-html="getDiff(request.request2, request.request1)"></pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<!--其他设置-->
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.other_config')"
|
||||
name="other"
|
||||
class="other-config"
|
||||
v-if="request.otherConfig">
|
||||
<el-table :data="request.otherConfig">
|
||||
<el-table-column prop="columnTitle" :label="$t('operating_log.change_field')" />
|
||||
<el-table-column prop="originalValue" :label="$t('operating_log.before_change')">
|
||||
<template v-slot:default="scope">
|
||||
<el-tooltip :content="scope.row.originalValue">
|
||||
<div class="current-value ms-tag-del">
|
||||
{{ scope.row.originalValue }}
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="newValue" :label="$t('operating_log.after_change')">
|
||||
<template v-slot:default="scope">
|
||||
<el-tooltip :content="scope.row.newValue">
|
||||
<div class="current-value ms-tag-add">
|
||||
{{ scope.row.newValue }}
|
||||
</div>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.response_template')"
|
||||
name="esbData"
|
||||
class="pane"
|
||||
v-if="request.backEsbDataStruct1 || request.backEsbDataStruct2">
|
||||
<pre v-html="getDiff(request.backEsbDataStruct2, request.backEsbDataStruct1)"></pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane
|
||||
:label="$t('api_test.definition.request.post_script')"
|
||||
name="backScript"
|
||||
class="pane"
|
||||
v-if="request.backScript1 || request.backScript2">
|
||||
<pre v-html="getDiff(request.backScript2, request.backScript1)"></pre>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsJsonCodeEdit from './json-view/ComparedEditor';
|
||||
import MsApiKeyValueDetail from './common/ApiKeyValueDetail';
|
||||
import MsCodeEdit from 'metersphere-frontend/src/components/MsCodeEdit';
|
||||
const jsondiffpatch = require('jsondiffpatch');
|
||||
const formattersHtml = jsondiffpatch.formatters.html;
|
||||
|
||||
export default {
|
||||
name: 'MsApiTcpParameters',
|
||||
components: { MsJsonCodeEdit, MsApiKeyValueDetail, MsCodeEdit },
|
||||
props: {
|
||||
request: {},
|
||||
basisData: {},
|
||||
moduleOptions: Array,
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
showScript: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
referenced: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
spanNum: 21,
|
||||
activeName: 'request',
|
||||
reportType: 'xml',
|
||||
isReloadData: false,
|
||||
refreshedXmlTable: true,
|
||||
currentProjectId: '',
|
||||
};
|
||||
},
|
||||
created() {
|
||||
if (
|
||||
this.request.body &&
|
||||
(this.request.body.jsonSchema || this.request.body.xml || this.request.body.raw_1 || this.request.body.raw_2)
|
||||
) {
|
||||
this.activeName = 'request';
|
||||
if (this.request.body.jsonSchema) {
|
||||
this.reportType = 'json';
|
||||
}
|
||||
if (this.request.body.xml) {
|
||||
this.reportType = 'xml';
|
||||
}
|
||||
if (this.request.body.raw_1 || this.request.body.raw_2) {
|
||||
this.reportType = 'raw';
|
||||
}
|
||||
} else if (this.request.query1 || this.request.query2) {
|
||||
this.activeName = 'parameters';
|
||||
} else if (this.request.request1 || this.request.request2) {
|
||||
this.activeName = 'request';
|
||||
} else if (this.request.script1 || this.request.script2) {
|
||||
this.activeName = 'script';
|
||||
} else if (this.request.otherConfig) {
|
||||
this.activeName = 'other';
|
||||
} else if (this.request.backEsbDataStruct1 || this.request.backEsbDataStruct2) {
|
||||
this.activeName = 'esbData';
|
||||
} else if (this.request.backScript1 || this.request.backScript2) {
|
||||
this.activeName = 'backScript';
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'request.headerId'() {
|
||||
if (this.request.body) {
|
||||
this.activeName = 'request';
|
||||
if (this.request.body.jsonSchema) {
|
||||
this.reportType = 'json';
|
||||
}
|
||||
if (this.request.body.xml) {
|
||||
this.reportType = 'xml';
|
||||
}
|
||||
if (this.request.body.raw_1 || this.request.body.raw_2) {
|
||||
this.reportType = 'raw';
|
||||
}
|
||||
} else if (this.request.query_1 || this.request.query_2) {
|
||||
this.activeName = 'parameters';
|
||||
} else if (this.request.request_1 || this.request.request_2) {
|
||||
this.activeName = 'request';
|
||||
} else if (this.request.script_1 || this.request.script_2) {
|
||||
this.activeName = 'script';
|
||||
} else if (this.request.other_config) {
|
||||
this.activeName = 'other';
|
||||
} else if (this.request.backEsbDataStruct_1 || this.request.backEsbDataStruct_2) {
|
||||
this.activeName = 'esbData';
|
||||
} else if (this.request.backScript_1 || this.request.backScript_2) {
|
||||
this.activeName = 'backScript';
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getDiff(v1, v2) {
|
||||
let delta = jsondiffpatch.diff(JSON.parse(v1), JSON.parse(v2));
|
||||
return formattersHtml.format(delta, JSON.parse(v1));
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tcp :deep(.el-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.send-request {
|
||||
padding: 0px 0;
|
||||
height: 300px;
|
||||
border: 1px #dcdfe6 solid;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ms-left-cell {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.ms-left-buttion {
|
||||
margin: 6px 0px 8px 30px;
|
||||
}
|
||||
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.ms-left-cell {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.ms-left-buttion {
|
||||
margin: 6px 0px 8px 30px;
|
||||
}
|
||||
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
:deep(.instructions-icon) {
|
||||
font-size: 14px !important;
|
||||
}
|
||||
|
||||
.request-tabs {
|
||||
margin: 20px;
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.other-config {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.current-value {
|
||||
display: inline-block;
|
||||
overflow-x: hidden;
|
||||
padding-bottom: 0;
|
||||
text-overflow: ellipsis;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.ms-tag-del {
|
||||
text-decoration: line-through;
|
||||
text-decoration-color: red;
|
||||
-moz-text-decoration-line: line-through;
|
||||
background: #f3e6e7;
|
||||
}
|
||||
|
||||
.ms-tag-add {
|
||||
background: #e2ecdc;
|
||||
}
|
||||
|
||||
@import '~jsondiffpatch/dist/formatters-styles/html.css';
|
||||
@import '~jsondiffpatch/dist/formatters-styles/annotated.css';
|
||||
</style>
|
|
@ -1,14 +0,0 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class EsbApiParams implements Serializable {
|
||||
private String id;
|
||||
|
||||
private String resourceId;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -1,340 +0,0 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EsbApiParamsExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public EsbApiParamsExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andIdIsNull() {
|
||||
addCriterion("id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIsNotNull() {
|
||||
addCriterion("id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdEqualTo(String value) {
|
||||
addCriterion("id =", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotEqualTo(String value) {
|
||||
addCriterion("id <>", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThan(String value) {
|
||||
addCriterion("id >", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("id >=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThan(String value) {
|
||||
addCriterion("id <", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThanOrEqualTo(String value) {
|
||||
addCriterion("id <=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLike(String value) {
|
||||
addCriterion("id like", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotLike(String value) {
|
||||
addCriterion("id not like", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIn(List<String> values) {
|
||||
addCriterion("id in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotIn(List<String> values) {
|
||||
addCriterion("id not in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdBetween(String value1, String value2) {
|
||||
addCriterion("id between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotBetween(String value1, String value2) {
|
||||
addCriterion("id not between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdIsNull() {
|
||||
addCriterion("resource_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdIsNotNull() {
|
||||
addCriterion("resource_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdEqualTo(String value) {
|
||||
addCriterion("resource_id =", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdNotEqualTo(String value) {
|
||||
addCriterion("resource_id <>", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdGreaterThan(String value) {
|
||||
addCriterion("resource_id >", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("resource_id >=", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdLessThan(String value) {
|
||||
addCriterion("resource_id <", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdLessThanOrEqualTo(String value) {
|
||||
addCriterion("resource_id <=", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdLike(String value) {
|
||||
addCriterion("resource_id like", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdNotLike(String value) {
|
||||
addCriterion("resource_id not like", value, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdIn(List<String> values) {
|
||||
addCriterion("resource_id in", values, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdNotIn(List<String> values) {
|
||||
addCriterion("resource_id not in", values, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdBetween(String value1, String value2) {
|
||||
addCriterion("resource_id between", value1, value2, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andResourceIdNotBetween(String value1, String value2) {
|
||||
addCriterion("resource_id not between", value1, value2, "resourceId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class EsbApiParamsWithBLOBs extends EsbApiParams implements Serializable {
|
||||
private String dataStruct;
|
||||
|
||||
private String frontedScript;
|
||||
|
||||
private String responseDataStruct;
|
||||
|
||||
private String backedScript;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum ApiImportPlatform {
|
||||
Metersphere, Postman, Swagger2, Plugin, Jmeter, Har, ESB
|
||||
Metersphere, Postman, Swagger2, Plugin, Jmeter, Har
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ public class DefinitionReference {
|
|||
public static Map<String, String> caseColumns = new LinkedHashMap<>();
|
||||
public static Map<String, String> jdbcColumns = new LinkedHashMap<>();
|
||||
public static Map<String, String> httpColumns = new LinkedHashMap<>();
|
||||
public static Map<String, String> esbColumns = new LinkedHashMap<>();
|
||||
public static Map<String, String> authColumns = new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
|
@ -16,7 +15,6 @@ public class DefinitionReference {
|
|||
caseColumns.clear();
|
||||
jdbcColumns.clear();
|
||||
httpColumns.clear();
|
||||
esbColumns.clear();
|
||||
authColumns.clear();
|
||||
definitionColumns.put("name", "接口名称");
|
||||
definitionColumns.put("createUser", "创建人");
|
||||
|
@ -64,18 +62,5 @@ public class DefinitionReference {
|
|||
authColumns.put("username", "用户名");
|
||||
authColumns.put("password", "密码");
|
||||
authColumns.put("encrypt", "加密");
|
||||
|
||||
//tcp esb 其他设置
|
||||
esbColumns.put("classname", "TCPClient");
|
||||
esbColumns.put("ctimeout", "连接(ms)");
|
||||
esbColumns.put("timeout", "响应(ms)");
|
||||
esbColumns.put("soLinger", "SO LINGER");
|
||||
esbColumns.put("eolByte", "行尾(EOL)子节值");
|
||||
esbColumns.put("username", "用户名");
|
||||
esbColumns.put("password", "密码");
|
||||
esbColumns.put("reUseConnection", "Re-use connection");
|
||||
esbColumns.put("closeConnection", "关闭连接");
|
||||
esbColumns.put("nodelay", "设置无延迟");
|
||||
esbColumns.put("connectEncoding", "Connect encoding");
|
||||
}
|
||||
}
|
|
@ -1,84 +1,81 @@
|
|||
import {Assertions} from "../../business/menu/function/ext/ApiTestModel";
|
||||
import {getUUID} from "metersphere-frontend/src/utils";
|
||||
import { Assertions } from "../../business/menu/function/ext/ApiTestModel";
|
||||
import { getUUID } from "metersphere-frontend/src/utils";
|
||||
|
||||
export function getProtocolFilter(protocolType) {
|
||||
if (protocolType === "HTTP") {
|
||||
return [
|
||||
{text: 'GET', value: 'GET'},
|
||||
{text: 'POST', value: 'POST'},
|
||||
{text: 'PUT', value: 'PUT'},
|
||||
{text: 'PATCH', value: 'PATCH'},
|
||||
{text: 'DELETE', value: 'DELETE'},
|
||||
{text: 'OPTIONS', value: 'OPTIONS'},
|
||||
{text: 'HEAD', value: 'HEAD'},
|
||||
{text: 'CONNECT', value: 'CONNECT'},
|
||||
{ text: "GET", value: "GET" },
|
||||
{ text: "POST", value: "POST" },
|
||||
{ text: "PUT", value: "PUT" },
|
||||
{ text: "PATCH", value: "PATCH" },
|
||||
{ text: "DELETE", value: "DELETE" },
|
||||
{ text: "OPTIONS", value: "OPTIONS" },
|
||||
{ text: "HEAD", value: "HEAD" },
|
||||
{ text: "CONNECT", value: "CONNECT" },
|
||||
];
|
||||
} else if (protocolType === "TCP") {
|
||||
return [
|
||||
{text: 'TCP', value: 'TCP'},
|
||||
{text: 'ESB', value: 'ESB'}
|
||||
];
|
||||
return [{ text: "TCP", value: "TCP" }];
|
||||
} else if (protocolType === "SQL") {
|
||||
return [
|
||||
{text: 'SQL', value: 'SQL'},
|
||||
];
|
||||
return [{ text: "SQL", value: "SQL" }];
|
||||
} else if (protocolType === "DUBBO") {
|
||||
return [
|
||||
{text: 'dubbo://', value: 'dubbo://'},
|
||||
];
|
||||
return [{ text: "dubbo://", value: "dubbo://" }];
|
||||
} else {
|
||||
return [
|
||||
{text: 'GET', value: 'GET'},
|
||||
{text: 'POST', value: 'POST'},
|
||||
{text: 'PUT', value: 'PUT'},
|
||||
{text: 'PATCH', value: 'PATCH'},
|
||||
{text: 'DELETE', value: 'DELETE'},
|
||||
{text: 'OPTIONS', value: 'OPTIONS'},
|
||||
{text: 'HEAD', value: 'HEAD'},
|
||||
{text: 'CONNECT', value: 'CONNECT'},
|
||||
{text: 'DUBBO', value: 'DUBBO'},
|
||||
{text: 'dubbo://', value: 'dubbo://'},
|
||||
{text: 'SQL', value: 'SQL'},
|
||||
{text: 'TCP', value: 'TCP'},
|
||||
{ text: "GET", value: "GET" },
|
||||
{ text: "POST", value: "POST" },
|
||||
{ text: "PUT", value: "PUT" },
|
||||
{ text: "PATCH", value: "PATCH" },
|
||||
{ text: "DELETE", value: "DELETE" },
|
||||
{ text: "OPTIONS", value: "OPTIONS" },
|
||||
{ text: "HEAD", value: "HEAD" },
|
||||
{ text: "CONNECT", value: "CONNECT" },
|
||||
{ text: "DUBBO", value: "DUBBO" },
|
||||
{ text: "dubbo://", value: "dubbo://" },
|
||||
{ text: "SQL", value: "SQL" },
|
||||
{ text: "TCP", value: "TCP" },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export function parse(item) {
|
||||
if (item.jsonPath) {
|
||||
item.jsonPath.forEach(node => {
|
||||
item.jsonPath.forEach((node) => {
|
||||
if (node.enable === undefined) {
|
||||
node.enable = item.enable;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (item.jsr223) {
|
||||
item.jsr223.forEach(node => {
|
||||
item.jsr223.forEach((node) => {
|
||||
if (node.enable === undefined) {
|
||||
node.enable = item.enable;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (item.regex) {
|
||||
item.regex.forEach(node => {
|
||||
item.regex.forEach((node) => {
|
||||
if (node.enable === undefined) {
|
||||
node.enable = item.enable;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (item.xpath2) {
|
||||
item.xpath2.forEach(node => {
|
||||
item.xpath2.forEach((node) => {
|
||||
if (node.enable === undefined) {
|
||||
node.enable = item.enable;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (item.duration && item.duration.value > 0) {
|
||||
if (item.duration.enable === undefined) {
|
||||
item.duration.enable = item.enable;
|
||||
}
|
||||
}
|
||||
if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) {
|
||||
if (
|
||||
item.document &&
|
||||
item.document.data &&
|
||||
(item.document.data.json.length > 0 || item.document.data.xml.length > 0)
|
||||
) {
|
||||
if (item.document.enable === undefined) {
|
||||
item.document.enable = item.enable;
|
||||
}
|
||||
|
@ -86,7 +83,7 @@ export function parse(item) {
|
|||
}
|
||||
|
||||
export function hisDataProcessing(array, request) {
|
||||
let assertions = new Assertions({id: getUUID()});
|
||||
let assertions = new Assertions({ id: getUUID() });
|
||||
if (!request.hashTree) {
|
||||
request.hashTree = [];
|
||||
}
|
||||
|
@ -118,16 +115,23 @@ export function hisDataProcessing(array, request) {
|
|||
if (item.duration && item.duration.value > 0) {
|
||||
assertions.duration = item.duration;
|
||||
}
|
||||
if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) {
|
||||
if (
|
||||
item.document &&
|
||||
item.document.data &&
|
||||
(item.document.data.json.length > 0 ||
|
||||
item.document.data.xml.length > 0)
|
||||
) {
|
||||
assertions.document = item.document;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertionsIndex.forEach(item => {
|
||||
const rmIndex = request.hashTree.findIndex((d) => d.id === item.id && d.resourceId === item.resourceId);
|
||||
assertionsIndex.forEach((item) => {
|
||||
const rmIndex = request.hashTree.findIndex(
|
||||
(d) => d.id === item.id && d.resourceId === item.resourceId
|
||||
);
|
||||
request.hashTree.splice(rmIndex, 1);
|
||||
})
|
||||
});
|
||||
|
||||
request.hashTree.push(assertions);
|
||||
}
|
||||
|
@ -136,14 +140,31 @@ export function stepCompute(array, request) {
|
|||
let preSize = 0;
|
||||
let postSize = 0;
|
||||
let ruleSize = 0;
|
||||
array.forEach(item => {
|
||||
if (["JSR223PreProcessor", "JDBCPreProcessor", "ConstantTimer"].indexOf(item.type) !== -1) {
|
||||
array.forEach((item) => {
|
||||
if (
|
||||
["JSR223PreProcessor", "JDBCPreProcessor", "ConstantTimer"].indexOf(
|
||||
item.type
|
||||
) !== -1
|
||||
) {
|
||||
preSize++;
|
||||
} else if (["JSR223PostProcessor", "JDBCPostProcessor", "Extract"].indexOf(item.type) !== -1) {
|
||||
} else if (
|
||||
["JSR223PostProcessor", "JDBCPostProcessor", "Extract"].indexOf(
|
||||
item.type
|
||||
) !== -1
|
||||
) {
|
||||
postSize++;
|
||||
} else if (item.type === "Assertions") {
|
||||
ruleSize = (item.jsonPath.length + item.jsr223.length + item.regex.length + item.xpath2.length);
|
||||
if (item.document && item.document.data && (item.document.data.json.length > 0 || item.document.data.xml.length > 0)) {
|
||||
ruleSize =
|
||||
item.jsonPath.length +
|
||||
item.jsr223.length +
|
||||
item.regex.length +
|
||||
item.xpath2.length;
|
||||
if (
|
||||
item.document &&
|
||||
item.document.data &&
|
||||
(item.document.data.json.length > 0 ||
|
||||
item.document.data.xml.length > 0)
|
||||
) {
|
||||
ruleSize++;
|
||||
}
|
||||
if (item.duration && item.duration.value > 0) {
|
||||
|
@ -151,42 +172,49 @@ export function stepCompute(array, request) {
|
|||
}
|
||||
ruleSize += item.text ? item.text.length : 0;
|
||||
}
|
||||
})
|
||||
});
|
||||
request.preSize = preSize;
|
||||
request.postSize = postSize;
|
||||
request.ruleSize = ruleSize;
|
||||
|
||||
}
|
||||
|
||||
export function mergeDocumentData(originalData, childMap) {
|
||||
originalData.forEach(item => {
|
||||
originalData.forEach((item) => {
|
||||
if (childMap && childMap.has(item.id)) {
|
||||
let sourceData = JSON.parse(JSON.stringify(item.children));
|
||||
item.children = JSON.parse(JSON.stringify(childMap.get(item.id)));
|
||||
item.children.forEach(target => {
|
||||
let index = sourceData.findIndex(source => source.id === target.id);
|
||||
item.children.forEach((target) => {
|
||||
let index = sourceData.findIndex((source) => source.id === target.id);
|
||||
if (index !== -1) {
|
||||
target.children = sourceData[index].children
|
||||
target.children = sourceData[index].children;
|
||||
}
|
||||
})
|
||||
});
|
||||
if (item.children && item.children.length > 0) {
|
||||
mergeDocumentData(item.children, childMap);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export function mergeRequestDocumentData(request) {
|
||||
if (request && request.hashTree && request.hashTree.length > 0) {
|
||||
let index = request.hashTree.findIndex(item => item.type === 'Assertions');
|
||||
let index = request.hashTree.findIndex(
|
||||
(item) => item.type === "Assertions"
|
||||
);
|
||||
if (index !== -1) {
|
||||
if (request.hashTree[index].document && request.hashTree[index].document.originalData && request.hashTree[index].document.tableData.size && request.hashTree[index].document.tableData.size !== 0) {
|
||||
mergeDocumentData(request.hashTree[index].document.originalData, request.hashTree[index].document.tableData);
|
||||
request.hashTree[index].document.data.json = request.hashTree[index].document.originalData;
|
||||
if (
|
||||
request.hashTree[index].document &&
|
||||
request.hashTree[index].document.originalData &&
|
||||
request.hashTree[index].document.tableData.size &&
|
||||
request.hashTree[index].document.tableData.size !== 0
|
||||
) {
|
||||
mergeDocumentData(
|
||||
request.hashTree[index].document.originalData,
|
||||
request.hashTree[index].document.tableData
|
||||
);
|
||||
request.hashTree[index].document.data.json =
|
||||
request.hashTree[index].document.originalData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue