refactor(接口测试): 完善接口详情参数校验

This commit is contained in:
AgAngle 2024-01-29 11:02:38 +08:00 committed by Craftsman
parent a3b6601968
commit a29046d303
8 changed files with 23 additions and 9 deletions

View File

@ -1,7 +1,8 @@
package io.metersphere.api.dto.request.assertion;
import com.fasterxml.jackson.annotation.JsonTypeName;
import jakarta.validation.constraints.Size;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/**
@ -18,7 +19,8 @@ public class MsResponseCodeAssertion extends MsAssertion {
* 不校验可搭配其他校验使用
* 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition}
*/
@Size(max = 50)
@NotBlank
@EnumValue(enumClass = io.metersphere.sdk.constants.MsAssertionCondition.class)
private String condition;
/**
* 匹配值

View File

@ -3,6 +3,7 @@ package io.metersphere.api.dto.request.assertion;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.util.List;
@ -40,6 +41,7 @@ public class MsResponseHeaderAssertion extends MsAssertion {
* 匹配条件
* 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition}
*/
@NotBlank
@EnumValue(enumClass = io.metersphere.sdk.constants.MsAssertionCondition.class)
private String condition;
/**

View File

@ -1,6 +1,8 @@
package io.metersphere.api.dto.request.assertion;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.util.List;
@ -29,6 +31,8 @@ public class MsVariableAssertion extends MsAssertion {
* 匹配条件
* 值为 MsAssertionCondition
*/
@NotBlank
@EnumValue(enumClass = io.metersphere.sdk.constants.MsAssertionCondition.class)
private String condition;
/**
* 匹配值

View File

@ -4,6 +4,7 @@ import io.metersphere.sdk.constants.MsAssertionCondition;
import io.metersphere.sdk.constants.ValueEnum;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
@ -40,6 +41,7 @@ public class MsDocumentAssertionElement {
* 匹配条件
* 取值参考 {@link MsAssertionCondition}
*/
@NotBlank
@EnumValue(enumClass = MsAssertionCondition.class)
private String condition;
/**

View File

@ -1,5 +1,7 @@
package io.metersphere.api.dto.request.assertion.body;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@ -19,6 +21,8 @@ public class MsJSONPathAssertionItem extends MsBodyAssertionItem {
* 匹配条件
* 取值参考 {@link io.metersphere.sdk.constants.MsAssertionCondition}
*/
@NotBlank
@EnumValue(enumClass = io.metersphere.sdk.constants.MsAssertionCondition.class)
private String condition;
/**
* 匹配值

View File

@ -3,6 +3,7 @@ package io.metersphere.api.dto.request.processors;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.metersphere.api.dto.request.http.KeyValueParam;
import io.metersphere.project.constants.ScriptLanguageType;
import io.metersphere.system.valid.EnumValue;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import lombok.Data;
@ -25,6 +26,7 @@ public class ScriptProcessor extends MsProcessor {
* {@link ScriptLanguageType}
*/
@Size(max = 20)
@EnumValue(enumClass = ScriptLanguageType.class)
private String scriptLanguage;
/**
* 是否启用公共脚本

View File

@ -30,7 +30,10 @@ public abstract class ScriptProcessorConverter extends MsProcessorConverter<Scri
// if (StringUtils.isNotEmpty(scriptProcessor.getScript())) {
// scriptProcessor.setScript(StringUtils.replace(scriptProcessor.getScript(), ENV_VARIABLE_EXPRESSION, "\"" + MS_RUNNING_ENV_PREFIX + evnId + ".\""));
// }
testElement.setProperty(JmeterProperty.CACHE_KEY, false);
// python js cache 打开
boolean cacheKey = StringUtils.equalsAny(scriptProcessor.getScriptLanguage(), ScriptLanguageType.PYTHON.getValue(), ScriptLanguageType.JAVASCRIPT.getValue());
testElement.setProperty(JmeterProperty.CACHE_KEY, cacheKey);
testElement.setProperty(TestElement.TEST_CLASS, testElement.getClass().getSimpleName());
testElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(JmeterAlias.TEST_BEAN_GUI));
testElement.setProperty(JmeterProperty.SCRIPT_LANGUAGE, scriptProcessor.getScriptLanguage());

View File

@ -35,12 +35,7 @@ public class ResponseCodeAssertionConverter extends AssertionConverter<MsRespons
String condition = msAssertion.getCondition();
assertion.setName(String.format("Response code %s %s", condition.toLowerCase().replace("_", ""), expectedValue));
MsAssertionCondition msAssertionCondition = MsAssertionCondition.valueOf(condition);
if (msAssertionCondition!= null) {
assertion.addTestString(generateRegexExpression(condition, expectedValue));
} else {
assertion.addTestString(expectedValue);
}
assertion.addTestString(generateRegexExpression(condition, expectedValue));
assertion.setToContainsType();
assertion.setTestFieldResponseCode();
return assertion;