chore: 规范命名

This commit is contained in:
fit2-zhao 2024-11-06 16:18:02 +08:00 committed by Craftsman
parent 645a00b3cf
commit 68f5fb6624
7 changed files with 30 additions and 24 deletions

View File

@ -2,6 +2,15 @@ package io.metersphere.api.constants.mockserver;
// mock匹配规则
public enum ParamConditionEnums {
EQUALS, NOT_EQUALS, CONTAINS, LENGTH_EQUALS, LENGTH_NOT_EQUALS, LENGTH_LARGE, LENGTH_SHOT, REGULAR_MATCH,
IS_EMPTY, IS_NOT_EMPTY, NOT_CONTAINS
EQUALS,
NOT_EQUALS,
CONTAINS,
LENGTH_EQUALS,
LENGTH_NOT_EQUALS,
LENGTH_LARGE,
LENGTH_SHOT,
REGULAR_MATCH,
IS_EMPTY,
IS_NOT_EMPTY,
NOT_CONTAINS
}

View File

@ -1,9 +0,0 @@
package io.metersphere.api.dto.mockserver;
import io.metersphere.api.domain.ApiDefinitionMockConfig;
import lombok.Data;
@Data
public class ApiMockConfigDTO extends ApiDefinitionMockConfig {
private boolean enable;
}

View File

@ -33,7 +33,7 @@ public class BodyParamMatchRule {
* x-www-form-urlencoded 请求体
* bodyType WWW_FORM 使用该字段
*/
private keyValueMatchRule wwwFormBody = new keyValueMatchRule();
private KeyValueMatchRule wwwFormBody = new KeyValueMatchRule();
/**
* json 请求体
* bodyType JSON 使用该字段

View File

@ -34,7 +34,6 @@ public class KeyValueInfo {
case REGULAR_MATCH -> value.matches(this.value);
case IS_EMPTY -> StringUtils.isBlank(value);
case IS_NOT_EMPTY -> StringUtils.isNotBlank(value);
default -> false;
};
} catch (Exception e) {
return false;

View File

@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map;
@Data
public class keyValueMatchRule {
public class KeyValueMatchRule {
@Schema(description = "是否是全部匹配 false为任意匹配")
private boolean isMatchAll;
@Schema(description = "匹配规则")

View File

@ -7,28 +7,35 @@ import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
//mock匹配规则
/**
* Mock匹配规则
*/
@Data
public class MockMatchRule implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "请求头匹配规则")
private keyValueMatchRule header = new keyValueMatchRule();
private KeyValueMatchRule header = new KeyValueMatchRule();
@Schema(description = "query参数匹配规则")
private keyValueMatchRule query = new keyValueMatchRule();
private KeyValueMatchRule query = new KeyValueMatchRule();
@Schema(description = "REST参数匹配规则")
private keyValueMatchRule rest = new keyValueMatchRule();
private KeyValueMatchRule rest = new KeyValueMatchRule();
@Schema(description = "body参数匹配规则")
private BodyParamMatchRule body = new BodyParamMatchRule();
public boolean keyValueMatch(String matchType, Map<String, String> matchParam) {
keyValueMatchRule matchRule = switch (matchType) {
KeyValueMatchRule matchRule = switch (matchType) {
case "header" -> header;
case "query" -> query;
case "rest" -> rest;
@ -55,7 +62,7 @@ public class MockMatchRule implements Serializable {
return body.matchJson(httpRequestParam.getJsonString());
case FORM_DATA:
MockFormDataBody formDataBody = body.getFormDataBody();
keyValueMatchRule formDataBodyRule = new keyValueMatchRule();
KeyValueMatchRule formDataBodyRule = new KeyValueMatchRule();
if (formDataBody != null) {
formDataBodyRule.setMatchAll(formDataBody.isMatchAll());
List<KeyValueInfo> matchRules = new ArrayList<>();

View File

@ -138,7 +138,7 @@ public class MockServerTestService {
public MockMatchRule genMockMatchRule(String valuePrefix, boolean hasQuery, boolean hasHeader, String bodyParamType, boolean matchAll) {
MockMatchRule mockMatchRule = new MockMatchRule();
keyValueMatchRule restMatchRule = new keyValueMatchRule();
KeyValueMatchRule restMatchRule = new KeyValueMatchRule();
restMatchRule.setMatchAll(matchAll);
restMatchRule.setMatchRules(new ArrayList<>() {{
this.add(new KeyValueInfo() {{
@ -153,7 +153,7 @@ public class MockServerTestService {
mockMatchRule.setRest(restMatchRule);
if (hasQuery) {
keyValueMatchRule queryMatchRule = new keyValueMatchRule();
KeyValueMatchRule queryMatchRule = new KeyValueMatchRule();
queryMatchRule.setMatchAll(matchAll);
queryMatchRule.setMatchRules(new ArrayList<>() {{
this.add(new KeyValueInfo() {{
@ -173,7 +173,7 @@ public class MockServerTestService {
}
if (hasHeader) {
keyValueMatchRule headerMatchRule = new keyValueMatchRule();
KeyValueMatchRule headerMatchRule = new KeyValueMatchRule();
headerMatchRule.setMatchAll(matchAll);
headerMatchRule.setMatchRules(new ArrayList<>() {{
this.add(new KeyValueInfo() {{
@ -195,7 +195,7 @@ public class MockServerTestService {
if (StringUtils.equalsIgnoreCase(bodyParamType, "www")) {
mockMatchRule.setBody(new BodyParamMatchRule() {{
this.setBodyType(Body.BodyType.WWW_FORM.name());
this.setWwwFormBody(new keyValueMatchRule() {{
this.setWwwFormBody(new KeyValueMatchRule() {{
this.setMatchAll(matchAll);
this.setMatchRules(new ArrayList<>() {{
this.add(new KeyValueInfo() {{