fix: 修复mock期望按钮提示错误、自定义脚本不支持更改环境变量的问题、性能测试找不到附件的问题

修复mock期望按钮提示错误、自定义脚本不支持更改环境变量的问题、性能测试找不到附件的问题
This commit is contained in:
song-tianyang 2021-05-28 11:18:32 +08:00 committed by 刘瑞斌
parent 56cf866494
commit 31df6e4d23
4 changed files with 42 additions and 1 deletions

View File

@ -3,11 +3,14 @@ package io.metersphere.api.dto.automation;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List;
@Getter @Getter
@Setter @Setter
public class ApiScenrioExportJmx { public class ApiScenrioExportJmx {
private String name; private String name;
private String jmx; private String jmx;
List<String> files;
public ApiScenrioExportJmx(String name, String jmx) { public ApiScenrioExportJmx(String name, String jmx) {
this.name = name; this.name = name;

View File

@ -3,8 +3,10 @@ package io.metersphere.api.dto.definition.request.processors;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType; import com.alibaba.fastjson.annotation.JSONType;
import io.metersphere.api.dto.RunningParamKeys;
import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.commons.constants.DelimiterConstants; import io.metersphere.commons.constants.DelimiterConstants;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -15,6 +17,7 @@ import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.HashTree;
import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -32,6 +35,27 @@ public class MsJSR223Processor extends MsTestElement {
@Override @Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) { public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
//替换Metersphere环境变量
if(StringUtils.isEmpty(this.getUseEnviroment())){
if(config.getConfig() != null){
if(config.getProjectId() != null){
String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid();
this.setUseEnviroment(evnId);
}else {
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
if(evnConfigList!=null && !evnConfigList.isEmpty()){
for (EnvironmentConfig configItem : evnConfigList) {
String evnId = configItem.getApiEnvironmentid();
this.setUseEnviroment(evnId);
break;
}
}
}
}
}
script = StringUtils.replace(script, RunningParamKeys.API_ENVIRONMENT_ID,"\""+RunningParamKeys.RUNNING_PARAMS_PREFIX+this.getUseEnviroment()+".\"");
// 非导出操作且不是启用状态则跳过执行 // 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable()) { if (!config.isOperating() && !this.isEnable()) {
return; return;

View File

@ -47,6 +47,7 @@ import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.FileOperationRequest; import io.metersphere.track.request.testplan.FileOperationRequest;
import io.metersphere.track.service.TestPlanScenarioCaseService; import io.metersphere.track.service.TestPlanScenarioCaseService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
@ -1657,6 +1658,19 @@ public class ApiAutomationService {
String jmx = generateJmx(item); String jmx = generateJmx(item);
if (StringUtils.isNotEmpty(jmx)) { if (StringUtils.isNotEmpty(jmx)) {
ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(jmx, null, true).getXml()); ApiScenrioExportJmx scenrioExportJmx = new ApiScenrioExportJmx(item.getName(), apiTestService.updateJmxString(jmx, null, true).getXml());
//扫描需要哪些文件
JmxInfoDTO dto = apiTestService.updateJmxString(jmx, item.getName(), true);
if(MapUtils.isNotEmpty(dto.getAttachFiles())){
List<String> fileList = new ArrayList<>();
for (String fileName: dto.getAttachFiles().values()) {
if(!fileList.contains(fileName)){
fileList.add(fileName);
}
}
if(!fileList.isEmpty()){
scenrioExportJmx.setFiles(fileList);
}
}
resList.add(scenrioExportJmx); resList.add(scenrioExportJmx);
} }
} }

View File

@ -42,7 +42,7 @@
<ms-table-operator-button :tip="$t('commons.copy')" icon="el-icon-copy-document" <ms-table-operator-button :tip="$t('commons.copy')" icon="el-icon-copy-document"
@exec="copyExpect(scope.row)" @exec="copyExpect(scope.row)"
/> />
<ms-table-operator-button :tip="$t('commons.edit')" icon="el-icon-delete" <ms-table-operator-button :tip="$t('commons.delete')" icon="el-icon-delete"
@exec="removeExpect(scope.row)" @exec="removeExpect(scope.row)"
/> />
</div> </div>