refactor(测试跟踪): 静态代码规范调整
This commit is contained in:
parent
04b4d7aa8d
commit
06418c23cb
|
@ -18,10 +18,18 @@ public class JMeterVars {
|
|||
private JMeterVars() {
|
||||
}
|
||||
|
||||
// 数据和线程变量保持一致
|
||||
/**
|
||||
* 数据和线程变量保持一致
|
||||
*/
|
||||
private static Map<Integer, JMeterVariables> variables = new HashMap<>();
|
||||
|
||||
// 线程执行过程调用提取变量值
|
||||
/**
|
||||
* 线程执行过程调用提取变量值
|
||||
*
|
||||
* @param testId
|
||||
* @param vars
|
||||
* @param extract
|
||||
*/
|
||||
public static void addVars(Integer testId, JMeterVariables vars, String extract) {
|
||||
JMeterVariables vs = new JMeterVariables();
|
||||
|
||||
|
@ -36,7 +44,11 @@ public class JMeterVars {
|
|||
variables.put(testId, vs);
|
||||
}
|
||||
|
||||
// 处理所有请求,有提取变量的请求增加后置脚本提取变量值
|
||||
/**
|
||||
* 处理所有请求,有提取变量的请求增加后置脚本提取变量值
|
||||
*
|
||||
* @param tree
|
||||
*/
|
||||
public static void addJSR223PostProcessor(HashTree tree) {
|
||||
for (Object key : tree.keySet()) {
|
||||
HashTree node = tree.get(key);
|
||||
|
|
|
@ -30,14 +30,25 @@ public class XmindCaseParser {
|
|||
private TestCaseService testCaseService;
|
||||
private String maintainer;
|
||||
private String projectId;
|
||||
private StringBuffer process; // 过程校验记录
|
||||
// 已存在用例名称
|
||||
/**
|
||||
* 过程校验记录
|
||||
*/
|
||||
private StringBuffer process;
|
||||
/**
|
||||
* 已存在用例名称
|
||||
*/
|
||||
private Set<String> testCaseNames;
|
||||
// 转换后的案例信息
|
||||
/**
|
||||
* 转换后的案例信息
|
||||
*/
|
||||
private List<TestCaseWithBLOBs> testCases;
|
||||
// 案例详情重写了hashCode方法去重用
|
||||
/**
|
||||
* 案例详情重写了hashCode方法去重用
|
||||
*/
|
||||
private List<TestCaseExcelData> compartDatas;
|
||||
// 记录没有用例的目录
|
||||
/**
|
||||
* 记录没有用例的目录
|
||||
*/
|
||||
private List<String> nodePaths;
|
||||
|
||||
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
|
||||
|
@ -89,7 +100,9 @@ public class XmindCaseParser {
|
|||
});
|
||||
}
|
||||
|
||||
// 递归处理案例数据
|
||||
/**
|
||||
* 递归处理案例数据
|
||||
*/
|
||||
private void recursion(Attached parent, int level, List<Attached> attacheds) {
|
||||
for (Attached item : attacheds) {
|
||||
if (isAvailable(item.getTitle(), TC_REGEX)) { // 用例
|
||||
|
@ -115,23 +128,27 @@ public class XmindCaseParser {
|
|||
}
|
||||
|
||||
private boolean isAvailable(String str, String regex) {
|
||||
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex))
|
||||
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex)) {
|
||||
return false;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher result = pattern.matcher(str);
|
||||
return result.find();
|
||||
}
|
||||
|
||||
private String replace(String str, String regex) {
|
||||
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex))
|
||||
if (StringUtils.isEmpty(str) || StringUtils.isEmpty(regex)) {
|
||||
return str;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher result = pattern.matcher(str);
|
||||
str = result.replaceAll("");
|
||||
return str;
|
||||
}
|
||||
|
||||
// 获取步骤数据
|
||||
/**
|
||||
* 获取步骤数据
|
||||
*/
|
||||
private String getSteps(List<Attached> attacheds) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (int i = 0; i < attacheds.size(); i++) {
|
||||
|
@ -147,7 +164,9 @@ public class XmindCaseParser {
|
|||
return jsonArray.toJSONString();
|
||||
}
|
||||
|
||||
// 初始化一个用例
|
||||
/**
|
||||
* 初始化一个用例
|
||||
*/
|
||||
private void newTestCase(String title, String nodePath, List<Attached> attacheds) {
|
||||
TestCaseWithBLOBs testCase = new TestCaseWithBLOBs();
|
||||
testCase.setProjectId(projectId);
|
||||
|
@ -157,7 +176,7 @@ public class XmindCaseParser {
|
|||
testCase.setType("functional");
|
||||
|
||||
String tc = title.replace(":", ":");
|
||||
String tcArr[] = tc.split(":");
|
||||
String[] tcArr = tc.split(":");
|
||||
if (tcArr.length != 2) {
|
||||
process.append(Translator.get("test_case_name") + "【 " + title + " 】" + Translator.get("incorrect_format"));
|
||||
return;
|
||||
|
@ -175,7 +194,7 @@ public class XmindCaseParser {
|
|||
|
||||
// 用例等级和用例性质处理
|
||||
if (tcArr[0].indexOf("-") != -1) {
|
||||
String otArr[] = tcArr[0].split("-");
|
||||
String[] otArr = tcArr[0].split("-");
|
||||
for (String item : otArr) {
|
||||
if (item.toUpperCase().startsWith("P")) {
|
||||
testCase.setPriority(item.toUpperCase());
|
||||
|
@ -222,7 +241,9 @@ public class XmindCaseParser {
|
|||
compartDatas.add(compartData);
|
||||
}
|
||||
|
||||
// 验证合法性
|
||||
/**
|
||||
* 验证合法性
|
||||
*/
|
||||
private boolean validate(TestCaseWithBLOBs data) {
|
||||
String nodePath = data.getNodePath();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
@ -265,7 +286,9 @@ public class XmindCaseParser {
|
|||
return true;
|
||||
}
|
||||
|
||||
// 导入思维导图处理
|
||||
/**
|
||||
* 导入思维导图处理
|
||||
*/
|
||||
public String parse(MultipartFile multipartFile) {
|
||||
try {
|
||||
// 获取思维导图内容
|
||||
|
@ -274,7 +297,8 @@ public class XmindCaseParser {
|
|||
if (root != null && root.getRootTopic() != null && root.getRootTopic().getChildren() != null) {
|
||||
// 判断是模块还是用例
|
||||
for (Attached item : root.getRootTopic().getChildren().getAttached()) {
|
||||
if (isAvailable(item.getTitle(), TC_REGEX)) { // 用例
|
||||
// 用例
|
||||
if (isAvailable(item.getTitle(), TC_REGEX)) {
|
||||
return replace(item.getTitle(), TC_REGEX) + ":" + Translator.get("test_case_create_module_fail");
|
||||
} else {
|
||||
String nodePath = item.getTitle();
|
||||
|
@ -288,7 +312,8 @@ public class XmindCaseParser {
|
|||
if (nodePath.endsWith("/")) {
|
||||
nodePath = nodePath.substring(0, nodePath.length() - 1);
|
||||
}
|
||||
nodePaths.add(nodePath); // 没有用例的路径
|
||||
// 没有用例的路径
|
||||
nodePaths.add(nodePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import io.metersphere.xmind.parser.pojo.JsonRootBean;
|
|||
import io.metersphere.xmind.utils.FileUtil;
|
||||
import org.apache.commons.compress.archivers.ArchiveException;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -21,9 +20,9 @@ import java.util.Objects;
|
|||
* @Description 解析主体
|
||||
*/
|
||||
public class XmindParser {
|
||||
public static final String xmindZenJson = "content.json";
|
||||
public static final String xmindLegacyContent = "content.xml";
|
||||
public static final String xmindLegacyComments = "comments.xml";
|
||||
public static final String CONTENT_JSON = "content.json";
|
||||
public static final String CONTENT_XML = "content.xml";
|
||||
public static final String COMMENTS_XML = "comments.xml";
|
||||
|
||||
/**
|
||||
* 解析脑图文件,返回content整合后的内容
|
||||
|
@ -38,8 +37,9 @@ public class XmindParser {
|
|||
File file = FileUtil.multipartFileToFile(multipartFile);
|
||||
List<String> contents = null;
|
||||
String res = null;
|
||||
if (file == null || !file.exists())
|
||||
if (file == null || !file.exists()) {
|
||||
MSException.throwException(Translator.get("incorrect_format"));
|
||||
}
|
||||
try {
|
||||
res = ZipUtils.extract(file);
|
||||
if (isXmindZen(res, file)) {
|
||||
|
@ -56,8 +56,9 @@ public class XmindParser {
|
|||
FileUtil.deleteDir(dir);
|
||||
}
|
||||
// 删除零时文件
|
||||
if (file != null)
|
||||
if (file != null) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
@ -86,9 +87,9 @@ public class XmindParser {
|
|||
public static List<String> getXmindZenContent(File file, String extractFileDir)
|
||||
throws IOException, ArchiveException {
|
||||
List<String> keys = new ArrayList<>();
|
||||
keys.add(xmindZenJson);
|
||||
keys.add(CONTENT_JSON);
|
||||
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
|
||||
String content = map.get(xmindZenJson);
|
||||
String content = map.get(CONTENT_JSON);
|
||||
return XmindZen.getContent(content);
|
||||
}
|
||||
|
||||
|
@ -98,12 +99,12 @@ public class XmindParser {
|
|||
public static List<String> getXmindLegacyContent(File file, String extractFileDir)
|
||||
throws IOException, ArchiveException, DocumentException {
|
||||
List<String> keys = new ArrayList<>();
|
||||
keys.add(xmindLegacyContent);
|
||||
keys.add(xmindLegacyComments);
|
||||
keys.add(CONTENT_XML);
|
||||
keys.add(COMMENTS_XML);
|
||||
Map<String, String> map = ZipUtils.getContents(keys, file, extractFileDir);
|
||||
|
||||
String contentXml = map.get(xmindLegacyContent);
|
||||
String commentsXml = map.get(xmindLegacyComments);
|
||||
String contentXml = map.get(CONTENT_XML);
|
||||
String commentsXml = map.get(COMMENTS_XML);
|
||||
List<String> xmlContent = XmindLegacy.getContent(contentXml, commentsXml);
|
||||
|
||||
return xmlContent;
|
||||
|
@ -115,7 +116,7 @@ public class XmindParser {
|
|||
if (parent.isDirectory()) {
|
||||
String[] files = parent.list(new ZipUtils.FileFilter());
|
||||
for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
|
||||
if (files[i].equals(xmindZenJson)) {
|
||||
if (files[i].equals(CONTENT_JSON)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Objects;
|
|||
*/
|
||||
public class ZipUtils {
|
||||
|
||||
private static final String currentPath = System.getProperty("user.dir");
|
||||
private static final String CURRENT_PATH = System.getProperty("user.dir");
|
||||
|
||||
/**
|
||||
* 找到压缩文件中匹配的子文件,返回的为 getContents("comments.xml, unzip
|
||||
|
@ -25,7 +25,7 @@ public class ZipUtils {
|
|||
public static Map<String, String> getContents(List<String> subFileNames, File file, String extractFileDir)
|
||||
throws IOException, ArchiveException {
|
||||
String destFilePath = extractFileDir;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, String> map = new HashMap<>(16);
|
||||
File destFile = new File(destFilePath);
|
||||
if (destFile.isDirectory()) {
|
||||
String[] res = destFile.list(new FileFilter());
|
||||
|
@ -49,12 +49,14 @@ public class ZipUtils {
|
|||
*/
|
||||
public static String extract(File file) throws IOException, ArchiveException {
|
||||
Expander expander = new Expander();
|
||||
String destFileName = currentPath + File.separator + "XMind" + System.currentTimeMillis(); // 目标文件夹名字
|
||||
String destFileName = CURRENT_PATH + File.separator + "XMind" + System.currentTimeMillis();
|
||||
expander.expand(file, new File(destFileName));
|
||||
return destFileName;
|
||||
}
|
||||
|
||||
// 这是一个内部类过滤器,策略模式
|
||||
/**
|
||||
* 这是一个内部类过滤器,策略模式
|
||||
*/
|
||||
static class FileFilter implements FilenameFilter {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
|
|
|
@ -8,9 +8,14 @@ import java.io.FileOutputStream;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
//获取流文件
|
||||
/**
|
||||
* 获取流文件
|
||||
*/
|
||||
private static void inputStreamToFile(InputStream ins, File file) {
|
||||
try (OutputStream os = new FileOutputStream(file);) {
|
||||
int bytesRead = 0;
|
||||
|
@ -57,5 +62,4 @@ public class FileUtil {
|
|||
return dir.delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue