fix(接口测试): 修复条件控制器添加后无法正确显示的bug
This commit is contained in:
parent
6baf28bed3
commit
f1dcd2191a
|
@ -1,7 +1,6 @@
|
||||||
package io.metersphere.api.dto.scenario.controller;
|
package io.metersphere.api.dto.scenario.controller;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class IfController {
|
public class IfController {
|
||||||
|
@ -11,46 +10,4 @@ public class IfController {
|
||||||
private String variable;
|
private String variable;
|
||||||
private String operator;
|
private String operator;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public boolean isValid() {
|
|
||||||
if (StringUtils.contains(operator, "empty")) {
|
|
||||||
return StringUtils.isNotBlank(variable);
|
|
||||||
}
|
|
||||||
return StringUtils.isNotBlank(variable) && StringUtils.isNotBlank(operator) && StringUtils.isNotBlank(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
if (isValid()) {
|
|
||||||
String label = variable + " " + operator;
|
|
||||||
if (StringUtils.isNotBlank(value)) {
|
|
||||||
label += " " + this.value;
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCondition() {
|
|
||||||
String variable = "\"" + this.variable + "\"";
|
|
||||||
String operator = this.operator;
|
|
||||||
String value = "\"" + this.value + "\"";
|
|
||||||
|
|
||||||
if (StringUtils.contains(operator, "~")) {
|
|
||||||
value = "\".*" + this.value + ".*\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.equals(operator, "is empty")) {
|
|
||||||
variable = "empty(" + variable + ")";
|
|
||||||
operator = "";
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.equals(operator, "is not empty")) {
|
|
||||||
variable = "!empty(" + variable + ")";
|
|
||||||
operator = "";
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "${__jexl3(" + variable + operator + value + ")}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
v-if="request.controller && request.controller.isValid()">
|
v-if="request.controller && request.controller.isValid()">
|
||||||
<el-row type="flex" align="middle">
|
<el-row type="flex" align="middle">
|
||||||
<font-awesome-icon :icon="['fas', 'random']"/>
|
<font-awesome-icon :icon="['fas', 'random']"/>
|
||||||
<div class="condition-label">{{ request.controller.label() }}</div>
|
<div class="condition-label">{{ request.controller.getLabel() }}</div>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
v-if="request.timer && request.timer.isValid()">
|
v-if="request.timer && request.timer.isValid()">
|
||||||
<el-row type="flex" align="middle">
|
<el-row type="flex" align="middle">
|
||||||
<font-awesome-icon :icon="['fas', 'clock']"/>
|
<font-awesome-icon :icon="['fas', 'clock']"/>
|
||||||
<div class="condition-label">{{ request.timer && request.timer.label() }}</div>
|
<div class="condition-label">{{ request.timer && request.timer.getLabel() }}</div>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -962,7 +962,7 @@ export class IfController extends Controller {
|
||||||
return !!this.variable && !!this.operator && !!this.value;
|
return !!this.variable && !!this.operator && !!this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
label() {
|
getLabel() {
|
||||||
if (this.isValid()) {
|
if (this.isValid()) {
|
||||||
let label = this.variable;
|
let label = this.variable;
|
||||||
if (this.operator) label += " " + this.operator;
|
if (this.operator) label += " " + this.operator;
|
||||||
|
@ -998,7 +998,7 @@ export class ConstantTimer extends Timer {
|
||||||
return this.delay > 0;
|
return this.delay > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
label() {
|
getLabel() {
|
||||||
if (this.isValid()) {
|
if (this.isValid()) {
|
||||||
return this.delay + " ms";
|
return this.delay + " ms";
|
||||||
}
|
}
|
||||||
|
@ -1362,14 +1362,14 @@ class JMXGenerator {
|
||||||
|
|
||||||
addConstantsTimer(sampler, request) {
|
addConstantsTimer(sampler, request) {
|
||||||
if (request.timer && request.timer.isValid() && request.timer.enable) {
|
if (request.timer && request.timer.isValid() && request.timer.enable) {
|
||||||
sampler.put(new JMXConstantTimer(request.timer.label(), request.timer));
|
sampler.put(new JMXConstantTimer(request.timer.getLabel(), request.timer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getController(sampler, request) {
|
getController(sampler, request) {
|
||||||
if (request.controller.isValid() && request.controller.enable) {
|
if (request.controller.isValid() && request.controller.enable) {
|
||||||
if (request.controller instanceof IfController) {
|
if (request.controller instanceof IfController) {
|
||||||
let name = request.controller.label();
|
let name = request.controller.getLabel();
|
||||||
let variable = "\"" + request.controller.variable + "\"";
|
let variable = "\"" + request.controller.variable + "\"";
|
||||||
let operator = request.controller.operator;
|
let operator = request.controller.operator;
|
||||||
let value = "\"" + request.controller.value + "\"";
|
let value = "\"" + request.controller.value + "\"";
|
||||||
|
|
Loading…
Reference in New Issue