feat: Mock服务功能开发完成

Mock服务功能开发完成
This commit is contained in:
song-tianyang 2021-04-15 18:38:24 +08:00
parent 03defc8950
commit d2b53fc94a
36 changed files with 3833 additions and 28 deletions

View File

@ -141,6 +141,13 @@
<version>1.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-rsocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-rsocket</artifactId>
<version>2.4.4</version>
</dependency>
<!-- jmeter -->
<dependency>

View File

@ -12,9 +12,11 @@ import io.metersphere.api.dto.definition.request.ScheduleInfoSwaggerUrlRequest;
import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult;
import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.api.service.EsbApiParamService;
import io.metersphere.api.service.EsbImportService;
import io.metersphere.base.domain.ApiDefinition;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.json.JSONSchemaGenerator;
@ -33,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.MalformedURLException;
import java.util.Date;
@ -53,6 +56,8 @@ public class ApiDefinitionController {
private EsbApiParamService esbApiParamService;
@Resource
private EsbImportService esbImportService;
@Resource
private ApiTestEnvironmentService apiTestEnvironmentService;
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
@ -264,4 +269,16 @@ public class ApiDefinitionController {
public void testCaseTemplateExport(HttpServletResponse response) {
esbImportService.templateExport(response);
}
@GetMapping("/getMockEnvironment/{projectId}")
public ApiTestEnvironmentWithBLOBs getMockEnvironment(@PathVariable String projectId, HttpServletRequest request) {
System.out.println(request.getRequestURL());
String requestUrl = request.getRequestURI();
String baseUrl = "";
if (requestUrl.contains("/api/definition")) {
baseUrl = requestUrl.split("/api/definition")[0];
}
return apiTestEnvironmentService.getMockEnvironmentByProjectId(projectId, baseUrl);
}
}

View File

@ -0,0 +1,187 @@
package io.metersphere.api.controller;
import io.metersphere.api.dto.mockconfig.response.MockConfigResponse;
import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.MockConfigService;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.annotation.ConnectMapping;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
/**
* @author song.tianyang
* @Date 2021/4/12 5:11 下午
* @Description
*/
@RestController
@RequestMapping("/mock")
public class MockApiController {
@Resource
private MockConfigService mockConfigService;
@Resource
private ApiDefinitionService apiDefinitionService;
@PostMapping("/{apiId}/**")
public String postRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getPostParamMap(request);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@GetMapping("/{apiId}/**")
public String getRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getGetParamMap(request, apiId);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@PutMapping("/{apiId}/**")
public String putRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getPostParamMap(request);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@PatchMapping("/{apiId}/**")
public String patchRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getPostParamMap(request);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@DeleteMapping("/{apiId}/**")
public String deleteRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getGetParamMap(request, apiId);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@RequestMapping(value = "/{apiId}/**", method = RequestMethod.OPTIONS)
public String optionsRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMapPost = mockConfigService.getPostParamMap(request);
Map<String, String> paramMapGet = mockConfigService.getGetParamMap(request, apiId);
Map<String, String> paramMap = new HashMap<>();
paramMap.putAll(paramMapPost);
paramMap.putAll(paramMapGet);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
return returnStr;
}
@RequestMapping(value = "/{apiId}/**", method = RequestMethod.HEAD)
public void headRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
Map<String, String> paramMap = mockConfigService.getGetParamMap(request, apiId);
String returnStr = "";
MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
response.setStatus(404);
if (finalExpectConfig != null) {
returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
}
}
}
// @ConnectMapping("/{apiId}/**")
// public String conntRequest(@PathVariable String apiId, HttpServletRequest request, HttpServletResponse response) {
// Enumeration<String> paramNameItor = request.getParameterNames();
//
// Map<String, String> paramMap = new HashMap<>();
// while (paramNameItor.hasMoreElements()) {
// String key = paramNameItor.nextElement();
// String value = request.getParameter(key);
// paramMap.put(key, value);
// }
//
// String returnStr = "";
// MockConfigResponse mockConfigData = mockConfigService.findByApiId(apiId);
// if (mockConfigData != null && mockConfigData.getMockExpectConfigList() != null) {
// MockExpectConfigResponse finalExpectConfig = mockConfigService.findExpectConfig(mockConfigData.getMockExpectConfigList(), paramMap);
// response.setStatus(404);
// if (finalExpectConfig != null) {
// returnStr = mockConfigService.updateHttpServletResponse(finalExpectConfig, response);
// }
// }
//
// return returnStr;
// }
private static final Map<String, RSocketRequester> REQUESTER_MAP = new HashMap<>();
@ConnectMapping("/{apiId}/**")
void onConnect(RSocketRequester rSocketRequester, @Payload String apiId) {
System.out.println("ooooooo");
rSocketRequester.rsocket()
.onClose()
.subscribe(null, null,
() -> REQUESTER_MAP.remove(apiId, rSocketRequester));
REQUESTER_MAP.put(apiId, rSocketRequester);
}
}

View File

@ -0,0 +1,61 @@
package io.metersphere.api.controller;
import io.metersphere.api.dto.mockconfig.MockConfigRequest;
import io.metersphere.api.dto.mockconfig.MockExpectConfigRequest;
import io.metersphere.api.dto.mockconfig.response.MockConfigResponse;
import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.MockConfigService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.MockExpectConfig;
import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* @author song.tianyang
* @Date 2021/4/12 5:11 下午
* @Description
*/
@RestController
@RequestMapping("/mockConfig")
public class MockConfigController {
@Resource
private MockConfigService mockConfigService;
@Resource
private ApiDefinitionService apiDefinitionService;
@PostMapping("/genMockConfig")
public MockConfigResponse genMockConfig(@RequestBody MockConfigRequest request) {
return mockConfigService.genMockConfig(request);
}
@PostMapping("/updateMockExpectConfig")
public MockExpectConfig updateMockExpectConfig(@RequestBody MockExpectConfigRequest request) {
return mockConfigService.updateMockExpectConfig(request);
}
@GetMapping("/mockExpectConfig/{id}")
public MockExpectConfigResponse selectMockExpectConfig(@PathVariable String id) {
MockExpectConfigWithBLOBs config = mockConfigService.findMockExpectConfigById(id);
MockExpectConfigResponse response = new MockExpectConfigResponse(config);
return response;
}
@GetMapping("/deleteMockExpectConfig/{id}")
public String deleteMockExpectConfig(@PathVariable String id) {
mockConfigService.deleteMockExpectConfig(id);
return "SUCCESS";
}
@GetMapping("/getApiParams/{id}")
public List<Map<String, String>> getApiParams(@PathVariable String id) {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionService.getBLOBs(id);
List<Map<String, String>> apiParams = mockConfigService.getApiParamsByApiDefinitionBLOBs(apiDefinitionWithBLOBs);
return apiParams;
}
}

View File

@ -639,7 +639,7 @@ public class ESBParser extends EsbAbstractParser {
MsJSR223PreProcessor preProcessor = new MsJSR223PreProcessor();
tcpSampler.setTcpPreProcessor(preProcessor);
tcpSampler.setProtocol("ESB");
tcpSampler.setClassname("TCPSampler");
tcpSampler.setClassname("TCPClientImpl");
return JSON.toJSONString(tcpSampler);
}

View File

@ -24,6 +24,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.service.ApiDefinitionService;
@ -110,6 +111,8 @@ public abstract class MsTestElement {
private boolean customizeReq;
@JSONField(ordinal = 12)
private String projectId;
@JSONField(ordinal = 13)
private boolean isMockEnvironment;
private MsTestElement parent;
@ -206,11 +209,16 @@ public abstract class MsTestElement {
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
if (environment != null && environment.getConfig() != null) {
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
isMockEnvironment = true;
}
// 单独接口执行
Map<String, EnvironmentConfig> map = new HashMap<>();
map.put(this.getProjectId(), JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class));
return map;
}
return null;
}

View File

@ -224,7 +224,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
sampler.setPath(urlObject.getPath());
} else {
sampler.setDomain(httpConfig.getDomain());
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
//1.9 增加对Mock环境的判断
if (this.isMockEnvironment()) {
url = url = httpConfig.getProtocol() + "://" + httpConfig.getSocket() + "/mock/" + this.getId();
} else {
url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
}
URL urlObject = new URL(url);
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
if (StringUtils.isNotBlank(this.getPath())) {

View File

@ -0,0 +1,17 @@
package io.metersphere.api.dto.mockconfig;
import lombok.Getter;
import lombok.Setter;
/**
* @author song.tianyang
* @Date 2021/4/13 4:00 下午
* @Description
*/
@Getter
@Setter
public class MockConfigRequest {
private String id;
private String apiId;
private String projectId;
}

View File

@ -0,0 +1,10 @@
package io.metersphere.api.dto.mockconfig;
/**
* @author song.tianyang
* @Date 2021/4/14 4:43 下午
* @Description
*/
public class MockConfigStaticData {
public static final String MOCK_EVN_NAME = "Mock环境";
}

View File

@ -0,0 +1,30 @@
package io.metersphere.api.dto.mockconfig;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author song.tianyang
* @Date 2021/4/13 4:00 下午
* @Description
*/
@Getter
@Setter
public class MockExpectConfigRequest {
private String id;
private String mockConfigId;
private String name;
private List<String> tags;
private Object request;
private Object response;
private String status;
}

View File

@ -0,0 +1,21 @@
package io.metersphere.api.dto.mockconfig.response;
import io.metersphere.base.domain.MockConfig;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author song.tianyang
* @Date 2021/4/13 4:59 下午
* @Description
*/
@Getter
@Setter
@AllArgsConstructor
public class MockConfigResponse {
private MockConfig mockConfig;
private List<MockExpectConfigResponse> mockExpectConfigList;
}

View File

@ -0,0 +1,59 @@
package io.metersphere.api.dto.mockconfig.response;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author song.tianyang
* @Date 2021/4/13 4:59 下午
* @Description
*/
@Getter
@Setter
public class MockExpectConfigResponse {
private String id;
private String mockConfigId;
private String name;
private List<String> tags;
private boolean status;
private Long createTime;
private Long updateTime;
private String createUserId;
private JSONObject request;
private JSONObject response;
public MockExpectConfigResponse(MockExpectConfigWithBLOBs expectConfig) {
this.id = expectConfig.getId();
this.mockConfigId = expectConfig.getMockConfigId();
this.name = expectConfig.getName();
this.status = Boolean.parseBoolean(expectConfig.getStatus());
this.createTime = expectConfig.getCreateTime();
this.updateTime = expectConfig.getUpdateTime();
this.createUserId = expectConfig.getCreateUserId();
this.request = JSONObject.parseObject(expectConfig.getRequest());
this.response = JSONObject.parseObject(expectConfig.getResponse());
if (expectConfig.getTags() != null) {
try {
tags = JSONArray.parseArray(expectConfig.getTags(), String.class);
} catch (Exception e) {
}
}
}
}

View File

@ -1363,7 +1363,7 @@ public class ApiAutomationService {
* 1将接口集合转化数据结构: map<url,List<id>> urlMap 用来做3的筛选
* 2将案例集合转化数据结构map<testCase.id,List<testCase.apiId>> caseIdMap 用来做2的筛选
* 3将接口集合转化数据结构: List<id> allApiIdList 用来做1的筛选
* 4自定义List<api.id> coveragedIdList 已覆盖的id集合 最终计算公式是 coveragedIdList/allApiIdList
* 4自定义List<api.id> coveragedIdList 已覆盖的id集合 最终计算公式是 coveragedIdList/allApiIdList
*
* 解析allScenarioList的scenarioDefinition字段
* 1提取每个步骤的url urlMap筛选

View File

@ -936,4 +936,5 @@ public class ApiDefinitionService {
public List<ApiDefinition> selectEffectiveIdByProjectId(String projectId) {
return extApiDefinitionMapper.selectEffectiveIdByProjectId(projectId);
}
}

View File

@ -1,5 +1,8 @@
package io.metersphere.api.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
import io.metersphere.base.domain.ApiTestEnvironmentExample;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
@ -10,7 +13,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Service
@ -65,4 +70,90 @@ public class ApiTestEnvironmentService {
}
}
}
/**
* 通过项目ID获取Mock环境 暂时定义mock环境为 name = Mock环境
*
* @param projectId
* @return
*/
public synchronized ApiTestEnvironmentWithBLOBs getMockEnvironmentByProjectId(String projectId, String baseUrl) {
String apiName = MockConfigStaticData.MOCK_EVN_NAME;
ApiTestEnvironmentWithBLOBs returnModel = null;
ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
example.createCriteria().andProjectIdEqualTo(projectId).andNameEqualTo(apiName);
List<ApiTestEnvironmentWithBLOBs> list = this.selectByExampleWithBLOBs(example);
if (list.isEmpty()) {
returnModel = this.genHttpApiTestEnvironmentByUrl(projectId, apiName, baseUrl);
this.add(returnModel);
} else {
returnModel = list.get(0);
}
return returnModel;
}
private ApiTestEnvironmentWithBLOBs genHttpApiTestEnvironmentByUrl(String projectId, String name, String url) {
String protocol = "";
if (url.startsWith("http://")) {
protocol = "http";
url = url.substring(7);
} else if (url.startsWith("https://")) {
protocol = "https";
url = url.substring(8);
}
String portStr = "";
String ipStr = protocol;
if (url.contains(":") && !url.endsWith(":")) {
String[] urlArr = url.split(":");
int port = -1;
try {
port = Integer.parseInt(urlArr[urlArr.length - 1]);
} catch (Exception e) {
}
if (port > -1) {
portStr = String.valueOf(port);
ipStr = urlArr[0];
}
}
JSONObject commonConfigObj = new JSONObject();
JSONArray variablesArr = new JSONArray();
Map<String, Object> map = new HashMap<>();
map.put("enable", true);
variablesArr.add(map);
commonConfigObj.put("variables", variablesArr);
commonConfigObj.put("enableHost", false);
commonConfigObj.put("hosts", new String[]{});
JSONObject httpConfig = new JSONObject();
httpConfig.put("socket", url);
httpConfig.put("domain", ipStr);
httpConfig.put("headers", variablesArr);
httpConfig.put("protocol", protocol);
if (StringUtils.isNotEmpty(portStr)) {
httpConfig.put("port", portStr);
}
JSONArray databaseConfigObj = new JSONArray();
JSONObject tcpConfigObj = new JSONObject();
tcpConfigObj.put("classname", "TCPClientImpl");
tcpConfigObj.put("reUseConnection", true);
tcpConfigObj.put("nodelay", false);
tcpConfigObj.put("closeConnection", false);
JSONObject object = new JSONObject();
object.put("commonConfig", commonConfigObj);
object.put("httpConfig", httpConfig);
object.put("databaseConfigs", databaseConfigObj);
object.put("tcpConfig", tcpConfigObj);
ApiTestEnvironmentWithBLOBs blobs = new ApiTestEnvironmentWithBLOBs();
blobs.setProjectId(projectId);
blobs.setName(name);
blobs.setConfig(object.toString());
return blobs;
}
}

View File

@ -0,0 +1,391 @@
package io.metersphere.api.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.api.dto.mockconfig.MockConfigRequest;
import io.metersphere.api.dto.mockconfig.MockExpectConfigRequest;
import io.metersphere.api.dto.mockconfig.response.MockConfigResponse;
import io.metersphere.api.dto.mockconfig.response.MockExpectConfigResponse;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiDefinitionMapper;
import io.metersphere.base.mapper.MockConfigMapper;
import io.metersphere.base.mapper.MockExpectConfigMapper;
import io.metersphere.commons.utils.SessionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
@Service
@Transactional(rollbackFor = Exception.class)
public class MockConfigService {
@Resource
private MockConfigMapper mockConfigMapper;
@Resource
private MockExpectConfigMapper mockExpectConfigMapper;
@Resource
private ApiDefinitionMapper apiDefinitionMapper;
public MockConfigResponse findByApiId(String apiId) {
MockConfigRequest request = new MockConfigRequest();
request.setApiId(apiId);
return this.genMockConfig(request);
}
public MockConfigResponse genMockConfig(MockConfigRequest request) {
MockConfigResponse returnRsp = null;
MockConfigExample example = new MockConfigExample();
MockConfigExample.Criteria criteria = example.createCriteria();
if (request.getId() != null) {
criteria.andIdEqualTo(request.getId());
}
if (request.getApiId() != null) {
criteria.andApiIdEqualTo(request.getApiId());
}
if (request.getProjectId() != null) {
criteria.andProjectIdEqualTo(request.getProjectId());
}
List<MockConfig> configList = mockConfigMapper.selectByExample(example);
if (configList.isEmpty()) {
long createTimeStmp = System.currentTimeMillis();
MockConfig config = new MockConfig();
config.setProjectId(request.getProjectId());
config.setApiId(request.getApiId());
config.setId(UUID.randomUUID().toString());
config.setCreateUserId(SessionUtils.getUserId());
config.setCreateTime(createTimeStmp);
config.setUpdateTime(createTimeStmp);
mockConfigMapper.insert(config);
returnRsp = new MockConfigResponse(config, new ArrayList<>());
} else {
MockConfig config = configList.get(0);
MockExpectConfigExample expectConfigExample = new MockExpectConfigExample();
expectConfigExample.createCriteria().andMockConfigIdEqualTo(config.getId());
expectConfigExample.setOrderByClause("update_time DESC");
List<MockExpectConfigResponse> expectConfigResponseList = new ArrayList<>();
List<MockExpectConfigWithBLOBs> expectConfigList = mockExpectConfigMapper.selectByExampleWithBLOBs(expectConfigExample);
for (MockExpectConfigWithBLOBs expectConfig :
expectConfigList) {
MockExpectConfigResponse response = new MockExpectConfigResponse(expectConfig);
expectConfigResponseList.add(response);
}
returnRsp = new MockConfigResponse(config, expectConfigResponseList);
}
return returnRsp;
}
public MockExpectConfig updateMockExpectConfig(MockExpectConfigRequest request) {
boolean isSave = false;
if (StringUtils.isEmpty(request.getId())) {
isSave = true;
request.setId(UUID.randomUUID().toString());
}
long timeStmp = System.currentTimeMillis();
MockExpectConfigWithBLOBs model = new MockExpectConfigWithBLOBs();
model.setId(request.getId());
model.setMockConfigId(request.getMockConfigId());
model.setUpdateTime(timeStmp);
model.setStatus(request.getStatus());
if (request.getTags() != null) {
model.setTags(JSONArray.toJSONString(request.getTags()));
}
model.setName(request.getName());
if (request.getRequest() != null) {
model.setRequest(JSONObject.toJSONString(request.getRequest()));
}
if (request.getResponse() != null) {
model.setResponse(JSONObject.toJSONString(request.getResponse()));
}
if (isSave) {
model.setCreateTime(timeStmp);
model.setCreateUserId(SessionUtils.getUserId());
model.setStatus("true");
mockExpectConfigMapper.insert(model);
} else {
mockExpectConfigMapper.updateByPrimaryKeySelective(model);
}
return model;
}
public MockExpectConfigResponse findExpectConfig(List<MockExpectConfigResponse> mockExpectConfigList, Map<String, String> paramMap) {
MockExpectConfigResponse returnModel = null;
if (paramMap == null || paramMap.isEmpty()) {
return returnModel;
}
for (MockExpectConfigResponse model : mockExpectConfigList) {
try {
if (!model.isStatus()) {
continue;
}
JSONObject requestObj = model.getRequest();
boolean isJsonParam = requestObj.getBoolean("jsonParam");
Map<String, String> reqParamMap = new HashMap<>();
if (isJsonParam) {
JSONObject jsonParam = JSONObject.parseObject(requestObj.getString("jsonData"));
for (String head : jsonParam.keySet()) {
reqParamMap.put(head.trim(), String.valueOf(jsonParam.get(head)).trim());
}
} else {
JSONArray jsonArray = requestObj.getJSONArray("variables");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
String name = "";
String value = "";
if (object.containsKey("name")) {
name = String.valueOf(object.get("name")).trim();
}
if (object.containsKey("value")) {
value = String.valueOf(object.get("value")).trim();
}
if (StringUtils.isNotEmpty(name)) {
reqParamMap.put(name, value);
}
}
}
boolean notMatching = false;
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
String key = entry.getKey().trim();
String value = entry.getValue();
if (value != null) {
value = value.trim();
}
if (!reqParamMap.containsKey(key) || !StringUtils.equals(value, reqParamMap.get(key))) {
notMatching = true;
break;
}
}
if (!notMatching) {
returnModel = model;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return returnModel;
}
public String updateHttpServletResponse(MockExpectConfigResponse finalExpectConfig, HttpServletResponse response) {
String returnStr = "";
try {
//设置响应头和响应码
JSONObject responseObj = finalExpectConfig.getResponse();
String httpCode = responseObj.getString("httpCode");
JSONArray jsonArray = responseObj.getJSONArray("httpHeads");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
String name = null;
String value = "";
if (object.containsKey("name")) {
name = String.valueOf(object.get("name")).trim();
}
if (object.containsKey("value")) {
value = String.valueOf(object.get("value")).trim();
}
if (StringUtils.isNotEmpty(name)) {
response.setHeader(name, value);
}
}
response.setStatus(Integer.parseInt(httpCode));
returnStr = String.valueOf(responseObj.get("body"));
if (responseObj.containsKey("delayed")) {
try {
long sleepTime = Long.parseLong(String.valueOf(responseObj.get("delayed")));
Thread.sleep(sleepTime);
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
return returnStr;
}
public MockExpectConfigWithBLOBs findMockExpectConfigById(String id) {
return mockExpectConfigMapper.selectByPrimaryKey(id);
}
public void deleteMockExpectConfig(String id) {
mockExpectConfigMapper.deleteByPrimaryKey(id);
}
public Map<String, String> getGetParamMap(HttpServletRequest request, String apiId) {
String urlPrefix = "/mock/" + apiId + "/";
String requestUri = request.getRequestURI();
String[] urlParamArr = requestUri.split(urlPrefix);
String urlParams = urlParamArr[urlParamArr.length - 1];
Map<String, String> paramMap = this.getSendRestParamMapByIdAndUrl(apiId, urlParams);
return paramMap;
}
public Map<String, String> getPostParamMap(HttpServletRequest request) {
Enumeration<String> paramNameItor = request.getParameterNames();
Map<String, String> paramMap = new HashMap<>();
while (paramNameItor.hasMoreElements()) {
String key = paramNameItor.nextElement();
String value = request.getParameter(key);
paramMap.put(key, value);
}
return paramMap;
}
public Map<String, String> getSendRestParamMapByIdAndUrl(String apiId, String urlParams) {
ApiDefinitionWithBLOBs api = apiDefinitionMapper.selectByPrimaryKey(apiId);
Map<String, String> returnMap = new HashMap<>();
if (api != null) {
String path = api.getPath();
String[] pathArr = path.split("/");
List<String> sendParams = new ArrayList<>();
for (String param : pathArr) {
if (param.startsWith("{") && param.endsWith("}")) {
param = param.substring(1, param.length() - 1);
sendParams.add(param);
}
}
try {
JSONObject requestJson = JSONObject.parseObject(api.getRequest());
if (requestJson.containsKey("rest")) {
JSONArray jsonArray = requestJson.getJSONArray("rest");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
if (object.containsKey("name") && object.containsKey("enable") && object.getBoolean("enable")) {
String name = object.getString("name");
if (sendParams.contains(name)) {
String value = "";
if (object.containsKey("value")) {
value = object.getString("value");
}
returnMap.put(name, value);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return returnMap;
}
public List<Map<String, String>> getApiParamsByApiDefinitionBLOBs(ApiDefinitionWithBLOBs apiModel) {
List<Map<String, String>> list = new ArrayList<>();
List<String> paramNameList = new ArrayList<>();
if (apiModel != null) {
if (apiModel.getRequest() != null) {
JSONObject requestObj = this.genJSONObject(apiModel.getRequest());
if (requestObj != null) {
//url参数赋值
if (requestObj.containsKey("arguments")) {
try {
JSONArray headArr = requestObj.getJSONArray("arguments");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && !paramNameList.contains(headObj.containsKey("name"))) {
paramNameList.add(String.valueOf(headObj.get("name")));
}
}
} catch (Exception e) {
}
}
if (requestObj.containsKey("rest")) {
try {
JSONArray headArr = requestObj.getJSONArray("rest");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && !paramNameList.contains(headObj.containsKey("name"))) {
paramNameList.add(String.valueOf(headObj.get("name")));
}
}
} catch (Exception e) {
}
}
//请求体参数类型
if (requestObj.containsKey("body")) {
try {
JSONObject bodyObj = requestObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
if (bodyObj.containsKey("kvs")) {
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
Map<String, String> previewObjMap = new LinkedHashMap<>();
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name") && !paramNameList.contains(kv.containsKey("name"))) {
paramNameList.add(String.valueOf(kv.get("name")));
}
}
}
} else if (StringUtils.equals(type, "BINARY")) {
if (bodyObj.containsKey("binary")) {
List<Map<String, String>> bodyParamList = new ArrayList<>();
JSONArray kvsArr = bodyObj.getJSONArray("binary");
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("description") && kv.containsKey("files")) {
String name = kv.getString("description");
JSONArray fileArr = kv.getJSONArray("files");
String value = "";
for (int j = 0; j < fileArr.size(); j++) {
JSONObject fileObj = fileArr.getJSONObject(j);
if (fileObj.containsKey("name")) {
value += fileObj.getString("name") + " ;";
}
}
if (!paramNameList.contains(name)) {
paramNameList.add(name);
}
}
}
}
}
}
} catch (Exception e) {
}
}
}
}
}
for (String param : paramNameList) {
Map<String, String> map = new HashMap<>();
map.put("value", param);
list.add(map);
}
return list;
}
private JSONObject genJSONObject(String request) {
JSONObject returnObj = null;
try {
returnObj = JSONObject.parseObject(request);
} catch (Exception e) {
}
return returnObj;
}
}

View File

@ -0,0 +1,26 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class MockConfig implements Serializable {
private String id;
private String projectId;
private String apiId;
private String apiPath;
private String apiMethod;
private Long createTime;
private Long updateTime;
private String createUserId;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,740 @@
package io.metersphere.base.domain;
import java.util.ArrayList;
import java.util.List;
public class MockConfigExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public MockConfigExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andProjectIdIsNull() {
addCriterion("project_id is null");
return (Criteria) this;
}
public Criteria andProjectIdIsNotNull() {
addCriterion("project_id is not null");
return (Criteria) this;
}
public Criteria andProjectIdEqualTo(String value) {
addCriterion("project_id =", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotEqualTo(String value) {
addCriterion("project_id <>", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdGreaterThan(String value) {
addCriterion("project_id >", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdGreaterThanOrEqualTo(String value) {
addCriterion("project_id >=", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLessThan(String value) {
addCriterion("project_id <", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLessThanOrEqualTo(String value) {
addCriterion("project_id <=", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdLike(String value) {
addCriterion("project_id like", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotLike(String value) {
addCriterion("project_id not like", value, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdIn(List<String> values) {
addCriterion("project_id in", values, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotIn(List<String> values) {
addCriterion("project_id not in", values, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdBetween(String value1, String value2) {
addCriterion("project_id between", value1, value2, "projectId");
return (Criteria) this;
}
public Criteria andProjectIdNotBetween(String value1, String value2) {
addCriterion("project_id not between", value1, value2, "projectId");
return (Criteria) this;
}
public Criteria andApiIdIsNull() {
addCriterion("api_id is null");
return (Criteria) this;
}
public Criteria andApiIdIsNotNull() {
addCriterion("api_id is not null");
return (Criteria) this;
}
public Criteria andApiIdEqualTo(String value) {
addCriterion("api_id =", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdNotEqualTo(String value) {
addCriterion("api_id <>", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdGreaterThan(String value) {
addCriterion("api_id >", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdGreaterThanOrEqualTo(String value) {
addCriterion("api_id >=", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdLessThan(String value) {
addCriterion("api_id <", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdLessThanOrEqualTo(String value) {
addCriterion("api_id <=", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdLike(String value) {
addCriterion("api_id like", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdNotLike(String value) {
addCriterion("api_id not like", value, "apiId");
return (Criteria) this;
}
public Criteria andApiIdIn(List<String> values) {
addCriterion("api_id in", values, "apiId");
return (Criteria) this;
}
public Criteria andApiIdNotIn(List<String> values) {
addCriterion("api_id not in", values, "apiId");
return (Criteria) this;
}
public Criteria andApiIdBetween(String value1, String value2) {
addCriterion("api_id between", value1, value2, "apiId");
return (Criteria) this;
}
public Criteria andApiIdNotBetween(String value1, String value2) {
addCriterion("api_id not between", value1, value2, "apiId");
return (Criteria) this;
}
public Criteria andApiPathIsNull() {
addCriterion("api_path is null");
return (Criteria) this;
}
public Criteria andApiPathIsNotNull() {
addCriterion("api_path is not null");
return (Criteria) this;
}
public Criteria andApiPathEqualTo(String value) {
addCriterion("api_path =", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathNotEqualTo(String value) {
addCriterion("api_path <>", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathGreaterThan(String value) {
addCriterion("api_path >", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathGreaterThanOrEqualTo(String value) {
addCriterion("api_path >=", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathLessThan(String value) {
addCriterion("api_path <", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathLessThanOrEqualTo(String value) {
addCriterion("api_path <=", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathLike(String value) {
addCriterion("api_path like", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathNotLike(String value) {
addCriterion("api_path not like", value, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathIn(List<String> values) {
addCriterion("api_path in", values, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathNotIn(List<String> values) {
addCriterion("api_path not in", values, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathBetween(String value1, String value2) {
addCriterion("api_path between", value1, value2, "apiPath");
return (Criteria) this;
}
public Criteria andApiPathNotBetween(String value1, String value2) {
addCriterion("api_path not between", value1, value2, "apiPath");
return (Criteria) this;
}
public Criteria andApiMethodIsNull() {
addCriterion("api_method is null");
return (Criteria) this;
}
public Criteria andApiMethodIsNotNull() {
addCriterion("api_method is not null");
return (Criteria) this;
}
public Criteria andApiMethodEqualTo(String value) {
addCriterion("api_method =", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodNotEqualTo(String value) {
addCriterion("api_method <>", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodGreaterThan(String value) {
addCriterion("api_method >", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodGreaterThanOrEqualTo(String value) {
addCriterion("api_method >=", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodLessThan(String value) {
addCriterion("api_method <", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodLessThanOrEqualTo(String value) {
addCriterion("api_method <=", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodLike(String value) {
addCriterion("api_method like", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodNotLike(String value) {
addCriterion("api_method not like", value, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodIn(List<String> values) {
addCriterion("api_method in", values, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodNotIn(List<String> values) {
addCriterion("api_method not in", values, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodBetween(String value1, String value2) {
addCriterion("api_method between", value1, value2, "apiMethod");
return (Criteria) this;
}
public Criteria andApiMethodNotBetween(String value1, String value2) {
addCriterion("api_method not between", value1, value2, "apiMethod");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Long value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Long value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Long value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Long value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Long value1, Long value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNull() {
addCriterion("update_time is null");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNotNull() {
addCriterion("update_time is not null");
return (Criteria) this;
}
public Criteria andUpdateTimeEqualTo(Long value) {
addCriterion("update_time =", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotEqualTo(Long value) {
addCriterion("update_time <>", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThan(Long value) {
addCriterion("update_time >", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("update_time >=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThan(Long value) {
addCriterion("update_time <", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThanOrEqualTo(Long value) {
addCriterion("update_time <=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIn(List<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> values) {
addCriterion("update_time not in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeBetween(Long value1, Long value2) {
addCriterion("update_time between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotBetween(Long value1, Long value2) {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andCreateUserIdIsNull() {
addCriterion("create_user_id is null");
return (Criteria) this;
}
public Criteria andCreateUserIdIsNotNull() {
addCriterion("create_user_id is not null");
return (Criteria) this;
}
public Criteria andCreateUserIdEqualTo(String value) {
addCriterion("create_user_id =", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotEqualTo(String value) {
addCriterion("create_user_id <>", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdGreaterThan(String value) {
addCriterion("create_user_id >", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdGreaterThanOrEqualTo(String value) {
addCriterion("create_user_id >=", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLessThan(String value) {
addCriterion("create_user_id <", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLessThanOrEqualTo(String value) {
addCriterion("create_user_id <=", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLike(String value) {
addCriterion("create_user_id like", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotLike(String value) {
addCriterion("create_user_id not like", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdIn(List<String> values) {
addCriterion("create_user_id in", values, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotIn(List<String> values) {
addCriterion("create_user_id not in", values, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdBetween(String value1, String value2) {
addCriterion("create_user_id between", value1, value2, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotBetween(String value1, String value2) {
addCriterion("create_user_id not between", value1, value2, "createUserId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -0,0 +1,26 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class MockExpectConfig implements Serializable {
private String id;
private String mockConfigId;
private String name;
private String tags;
private String status;
private Long createTime;
private Long updateTime;
private String createUserId;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,740 @@
package io.metersphere.base.domain;
import java.util.ArrayList;
import java.util.List;
public class MockExpectConfigExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public MockExpectConfigExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andMockConfigIdIsNull() {
addCriterion("mock_config_id is null");
return (Criteria) this;
}
public Criteria andMockConfigIdIsNotNull() {
addCriterion("mock_config_id is not null");
return (Criteria) this;
}
public Criteria andMockConfigIdEqualTo(String value) {
addCriterion("mock_config_id =", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdNotEqualTo(String value) {
addCriterion("mock_config_id <>", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdGreaterThan(String value) {
addCriterion("mock_config_id >", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdGreaterThanOrEqualTo(String value) {
addCriterion("mock_config_id >=", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdLessThan(String value) {
addCriterion("mock_config_id <", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdLessThanOrEqualTo(String value) {
addCriterion("mock_config_id <=", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdLike(String value) {
addCriterion("mock_config_id like", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdNotLike(String value) {
addCriterion("mock_config_id not like", value, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdIn(List<String> values) {
addCriterion("mock_config_id in", values, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdNotIn(List<String> values) {
addCriterion("mock_config_id not in", values, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdBetween(String value1, String value2) {
addCriterion("mock_config_id between", value1, value2, "mockConfigId");
return (Criteria) this;
}
public Criteria andMockConfigIdNotBetween(String value1, String value2) {
addCriterion("mock_config_id not between", value1, value2, "mockConfigId");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("`name` is null");
return (Criteria) this;
}
public Criteria andNameIsNotNull() {
addCriterion("`name` is not null");
return (Criteria) this;
}
public Criteria andNameEqualTo(String value) {
addCriterion("`name` =", value, "name");
return (Criteria) this;
}
public Criteria andNameNotEqualTo(String value) {
addCriterion("`name` <>", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThan(String value) {
addCriterion("`name` >", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("`name` >=", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThan(String value) {
addCriterion("`name` <", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("`name` <=", value, "name");
return (Criteria) this;
}
public Criteria andNameLike(String value) {
addCriterion("`name` like", value, "name");
return (Criteria) this;
}
public Criteria andNameNotLike(String value) {
addCriterion("`name` not like", value, "name");
return (Criteria) this;
}
public Criteria andNameIn(List<String> values) {
addCriterion("`name` in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> values) {
addCriterion("`name` not in", values, "name");
return (Criteria) this;
}
public Criteria andNameBetween(String value1, String value2) {
addCriterion("`name` between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("`name` not between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andTagsIsNull() {
addCriterion("tags is null");
return (Criteria) this;
}
public Criteria andTagsIsNotNull() {
addCriterion("tags is not null");
return (Criteria) this;
}
public Criteria andTagsEqualTo(String value) {
addCriterion("tags =", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotEqualTo(String value) {
addCriterion("tags <>", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThan(String value) {
addCriterion("tags >", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThanOrEqualTo(String value) {
addCriterion("tags >=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThan(String value) {
addCriterion("tags <", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThanOrEqualTo(String value) {
addCriterion("tags <=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLike(String value) {
addCriterion("tags like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotLike(String value) {
addCriterion("tags not like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsIn(List<String> values) {
addCriterion("tags in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsNotIn(List<String> values) {
addCriterion("tags not in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsBetween(String value1, String value2) {
addCriterion("tags between", value1, value2, "tags");
return (Criteria) this;
}
public Criteria andTagsNotBetween(String value1, String value2) {
addCriterion("tags not between", value1, value2, "tags");
return (Criteria) this;
}
public Criteria andStatusIsNull() {
addCriterion("`STATUS` is null");
return (Criteria) this;
}
public Criteria andStatusIsNotNull() {
addCriterion("`STATUS` is not null");
return (Criteria) this;
}
public Criteria andStatusEqualTo(String value) {
addCriterion("`STATUS` =", value, "status");
return (Criteria) this;
}
public Criteria andStatusNotEqualTo(String value) {
addCriterion("`STATUS` <>", value, "status");
return (Criteria) this;
}
public Criteria andStatusGreaterThan(String value) {
addCriterion("`STATUS` >", value, "status");
return (Criteria) this;
}
public Criteria andStatusGreaterThanOrEqualTo(String value) {
addCriterion("`STATUS` >=", value, "status");
return (Criteria) this;
}
public Criteria andStatusLessThan(String value) {
addCriterion("`STATUS` <", value, "status");
return (Criteria) this;
}
public Criteria andStatusLessThanOrEqualTo(String value) {
addCriterion("`STATUS` <=", value, "status");
return (Criteria) this;
}
public Criteria andStatusLike(String value) {
addCriterion("`STATUS` like", value, "status");
return (Criteria) this;
}
public Criteria andStatusNotLike(String value) {
addCriterion("`STATUS` not like", value, "status");
return (Criteria) this;
}
public Criteria andStatusIn(List<String> values) {
addCriterion("`STATUS` in", values, "status");
return (Criteria) this;
}
public Criteria andStatusNotIn(List<String> values) {
addCriterion("`STATUS` not in", values, "status");
return (Criteria) this;
}
public Criteria andStatusBetween(String value1, String value2) {
addCriterion("`STATUS` between", value1, value2, "status");
return (Criteria) this;
}
public Criteria andStatusNotBetween(String value1, String value2) {
addCriterion("`STATUS` not between", value1, value2, "status");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Long value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Long value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Long value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Long value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Long value1, Long value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNull() {
addCriterion("update_time is null");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNotNull() {
addCriterion("update_time is not null");
return (Criteria) this;
}
public Criteria andUpdateTimeEqualTo(Long value) {
addCriterion("update_time =", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotEqualTo(Long value) {
addCriterion("update_time <>", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThan(Long value) {
addCriterion("update_time >", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("update_time >=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThan(Long value) {
addCriterion("update_time <", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThanOrEqualTo(Long value) {
addCriterion("update_time <=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIn(List<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> values) {
addCriterion("update_time not in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeBetween(Long value1, Long value2) {
addCriterion("update_time between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotBetween(Long value1, Long value2) {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andCreateUserIdIsNull() {
addCriterion("create_user_id is null");
return (Criteria) this;
}
public Criteria andCreateUserIdIsNotNull() {
addCriterion("create_user_id is not null");
return (Criteria) this;
}
public Criteria andCreateUserIdEqualTo(String value) {
addCriterion("create_user_id =", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotEqualTo(String value) {
addCriterion("create_user_id <>", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdGreaterThan(String value) {
addCriterion("create_user_id >", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdGreaterThanOrEqualTo(String value) {
addCriterion("create_user_id >=", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLessThan(String value) {
addCriterion("create_user_id <", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLessThanOrEqualTo(String value) {
addCriterion("create_user_id <=", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdLike(String value) {
addCriterion("create_user_id like", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotLike(String value) {
addCriterion("create_user_id not like", value, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdIn(List<String> values) {
addCriterion("create_user_id in", values, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotIn(List<String> values) {
addCriterion("create_user_id not in", values, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdBetween(String value1, String value2) {
addCriterion("create_user_id between", value1, value2, "createUserId");
return (Criteria) this;
}
public Criteria andCreateUserIdNotBetween(String value1, String value2) {
addCriterion("create_user_id not between", value1, value2, "createUserId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -0,0 +1,18 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MockExpectConfigWithBLOBs extends MockExpectConfig implements Serializable {
private String request;
private String response;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,32 @@
package io.metersphere.base.mapper;
import io.metersphere.base.domain.MockConfig;
import io.metersphere.base.domain.MockConfigExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface MockConfigMapper {
long countByExample(MockConfigExample example);
int deleteByExample(MockConfigExample example);
int deleteByPrimaryKey(String id);
int insert(MockConfig record);
int insertSelective(MockConfig record);
List<MockConfig> selectByExample(MockConfigExample example);
MockConfig selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") MockConfig record, @Param("example") MockConfigExample example);
int updateByExample(@Param("record") MockConfig record, @Param("example") MockConfigExample example);
int updateByPrimaryKeySelective(MockConfig record);
int updateByPrimaryKey(MockConfig record);
}

View File

@ -0,0 +1,262 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.MockConfigMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.MockConfig">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="project_id" jdbcType="VARCHAR" property="projectId"/>
<result column="api_id" jdbcType="VARCHAR" property="apiId"/>
<result column="api_path" jdbcType="VARCHAR" property="apiPath"/>
<result column="api_method" jdbcType="VARCHAR" property="apiMethod"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, project_id, api_id, api_path, api_method, create_time, update_time, create_user_id
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.MockConfigExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from mock_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from mock_config
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete
from mock_config
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockConfigExample">
delete from mock_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.MockConfig">
insert into mock_config (id, project_id, api_id,
api_path, api_method, create_time,
update_time, create_user_id)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{apiId,jdbcType=VARCHAR},
#{apiPath,jdbcType=VARCHAR}, #{apiMethod,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MockConfig">
insert into mock_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="projectId != null">
project_id,
</if>
<if test="apiId != null">
api_id,
</if>
<if test="apiPath != null">
api_path,
</if>
<if test="apiMethod != null">
api_method,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createUserId != null">
create_user_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="projectId != null">
#{projectId,jdbcType=VARCHAR},
</if>
<if test="apiId != null">
#{apiId,jdbcType=VARCHAR},
</if>
<if test="apiPath != null">
#{apiPath,jdbcType=VARCHAR},
</if>
<if test="apiMethod != null">
#{apiMethod,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
#{createUserId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.MockConfigExample"
resultType="java.lang.Long">
select count(*) from mock_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update mock_config
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.projectId != null">
project_id = #{record.projectId,jdbcType=VARCHAR},
</if>
<if test="record.apiId != null">
api_id = #{record.apiId,jdbcType=VARCHAR},
</if>
<if test="record.apiPath != null">
api_path = #{record.apiPath,jdbcType=VARCHAR},
</if>
<if test="record.apiMethod != null">
api_method = #{record.apiMethod,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
update mock_config
set id = #{record.id,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
api_id = #{record.apiId,jdbcType=VARCHAR},
api_path = #{record.apiPath,jdbcType=VARCHAR},
api_method = #{record.apiMethod,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockConfig">
update mock_config
<set>
<if test="projectId != null">
project_id = #{projectId,jdbcType=VARCHAR},
</if>
<if test="apiId != null">
api_id = #{apiId,jdbcType=VARCHAR},
</if>
<if test="apiPath != null">
api_path = #{apiPath,jdbcType=VARCHAR},
</if>
<if test="apiMethod != null">
api_method = #{apiMethod,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.MockConfig">
update mock_config
set project_id = #{projectId,jdbcType=VARCHAR},
api_id = #{apiId,jdbcType=VARCHAR},
api_path = #{apiPath,jdbcType=VARCHAR},
api_method = #{apiMethod,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -0,0 +1,39 @@
package io.metersphere.base.mapper;
import io.metersphere.base.domain.MockExpectConfig;
import io.metersphere.base.domain.MockExpectConfigExample;
import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface MockExpectConfigMapper {
long countByExample(MockExpectConfigExample example);
int deleteByExample(MockExpectConfigExample example);
int deleteByPrimaryKey(String id);
int insert(MockExpectConfigWithBLOBs record);
int insertSelective(MockExpectConfigWithBLOBs record);
List<MockExpectConfigWithBLOBs> selectByExampleWithBLOBs(MockExpectConfigExample example);
List<MockExpectConfig> selectByExample(MockExpectConfigExample example);
MockExpectConfigWithBLOBs selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") MockExpectConfigWithBLOBs record, @Param("example") MockExpectConfigExample example);
int updateByExampleWithBLOBs(@Param("record") MockExpectConfigWithBLOBs record, @Param("example") MockExpectConfigExample example);
int updateByExample(@Param("record") MockExpectConfig record, @Param("example") MockExpectConfigExample example);
int updateByPrimaryKeySelective(MockExpectConfigWithBLOBs record);
int updateByPrimaryKeyWithBLOBs(MockExpectConfigWithBLOBs record);
int updateByPrimaryKey(MockExpectConfig record);
}

View File

@ -0,0 +1,345 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.MockExpectConfigMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.MockExpectConfig">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="mock_config_id" jdbcType="VARCHAR" property="mockConfigId"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="tags" jdbcType="VARCHAR" property="tags"/>
<result column="STATUS" jdbcType="VARCHAR" property="status"/>
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
<result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
type="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
<result column="request" jdbcType="LONGVARCHAR" property="request"/>
<result column="response" jdbcType="LONGVARCHAR" property="response"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, mock_config_id, `name`, tags, `STATUS`, create_time, update_time, create_user_id
</sql>
<sql id="Blob_Column_List">
request, response
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigExample"
resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from mock_expect_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample"
resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from mock_expect_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from mock_expect_config
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete
from mock_expect_config
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample">
delete from mock_expect_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
insert into mock_expect_config (id, mock_config_id, `name`,
tags, `STATUS`, create_time,
update_time, create_user_id, request,
response)
values (#{id,jdbcType=VARCHAR}, #{mockConfigId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{tags,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{request,jdbcType=LONGVARCHAR},
#{response,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
insert into mock_expect_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="mockConfigId != null">
mock_config_id,
</if>
<if test="name != null">
`name`,
</if>
<if test="tags != null">
tags,
</if>
<if test="status != null">
`STATUS`,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createUserId != null">
create_user_id,
</if>
<if test="request != null">
request,
</if>
<if test="response != null">
response,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="mockConfigId != null">
#{mockConfigId,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="tags != null">
#{tags,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
#{createUserId,jdbcType=VARCHAR},
</if>
<if test="request != null">
#{request,jdbcType=LONGVARCHAR},
</if>
<if test="response != null">
#{response,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.MockExpectConfigExample"
resultType="java.lang.Long">
select count(*) from mock_expect_config
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update mock_expect_config
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.mockConfigId != null">
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.tags != null">
tags = #{record.tags,jdbcType=VARCHAR},
</if>
<if test="record.status != null">
`STATUS` = #{record.status,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.createUserId != null">
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
</if>
<if test="record.request != null">
request = #{record.request,jdbcType=LONGVARCHAR},
</if>
<if test="record.response != null">
response = #{record.response,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
update mock_expect_config
set id = #{record.id,jdbcType=VARCHAR},
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR},
`STATUS` = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR},
request = #{record.request,jdbcType=LONGVARCHAR},
response = #{record.response,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
update mock_expect_config
set id = #{record.id,jdbcType=VARCHAR},
mock_config_id = #{record.mockConfigId,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
tags = #{record.tags,jdbcType=VARCHAR},
`STATUS` = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT},
create_user_id = #{record.createUserId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
update mock_expect_config
<set>
<if test="mockConfigId != null">
mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="tags != null">
tags = #{tags,jdbcType=VARCHAR},
</if>
<if test="status != null">
`STATUS` = #{status,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="createUserId != null">
create_user_id = #{createUserId,jdbcType=VARCHAR},
</if>
<if test="request != null">
request = #{request,jdbcType=LONGVARCHAR},
</if>
<if test="response != null">
response = #{response,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
update mock_expect_config
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR},
request = #{request,jdbcType=LONGVARCHAR},
response = #{response,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.MockExpectConfig">
update mock_expect_config
set mock_config_id = #{mockConfigId,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
`STATUS` = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
create_user_id = #{createUserId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -50,6 +50,8 @@ public class ShiroUtils {
filterChainDefinitionMap.put("/v1/catalog/**", "anon");
filterChainDefinitionMap.put("/v1/agent/**", "anon");
filterChainDefinitionMap.put("/v1/health/**", "anon");
//mock接口
filterChainDefinitionMap.put("/mock/**", "anon");
}
public static void ignoreCsrfFilter(Map<String, String> filterChainDefinitionMap) {
@ -57,6 +59,7 @@ public class ShiroUtils {
filterChainDefinitionMap.put("/language", "apikey, authc");// 跳转到 /language 不用校验 csrf
filterChainDefinitionMap.put("/document", "apikey, authc"); // 跳转到 /document 不用校验 csrf
filterChainDefinitionMap.put("/test/case/file/preview/**", "apikey, authc"); // 预览测试用例附件 不用校验 csrf
filterChainDefinitionMap.put("/mock", "apikey, authc"); // 跳转到 /mock接口 不用校验 csrf
}
public static Cookie getSessionIdCookie(){

View File

@ -121,8 +121,10 @@ VALUES ('b8921cbc-05b3-4d8f-a96e-d1e4ae9d8664','a577bc60-75fe-47ec-8aa6-32dca23b
INSERT INTO custom_field_template (id,field_id,template_id,scene,required,default_value)
VALUES ('d5908553-1b29-4868-9001-e938822b92ef','beb57501-19c8-4ca3-8dfb-2cef7c0ea087','5d7c87d2-f405-4ec1-9a3d-71b514cdfda3','ISSUE',1,'"NEW"');
ALTER TABLE project ADD case_template_id varchar(50) NULL COMMENT 'Relate test case template id';
ALTER TABLE project ADD issue_template_id varchar(50) NULL COMMENT 'Relate test issue template id';
ALTER TABLE project
ADD case_template_id varchar(50) NULL COMMENT 'Relate test case template id';
ALTER TABLE project
ADD issue_template_id varchar(50) NULL COMMENT 'Relate test issue template id';
-- add test_case
alter table test_case
@ -131,6 +133,42 @@ alter table test_case
add expected_result text null;
-- api_scenario_report modify column length
ALTER TABLE api_scenario_report MODIFY COLUMN name VARCHAR(3000);
ALTER TABLE api_scenario_report
MODIFY COLUMN name VARCHAR(3000);
-- api_scenario_report modify column length
ALTER TABLE api_scenario_report MODIFY COLUMN scenario_id VARCHAR(3000);
ALTER TABLE api_scenario_report
MODIFY COLUMN scenario_id VARCHAR(3000);
-- create mock config
CREATE TABLE IF NOT EXISTS `mock_config`
(
id varchar(50) not null,
project_id varchar(50) not null,
api_id varchar(50) not null,
api_path varchar(1000) null,
api_method varchar(64) null,
create_time bigint(13) null,
update_time bigint(13) null,
create_user_id VARCHAR(64) null,
primary key (id),
INDEX `api_id` (`api_id`) USING BTREE,
INDEX `project_id` (`project_id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE IF NOT EXISTS `mock_expect_config`
(
id varchar(50) not null,
mock_config_id varchar(50) null,
`name` varchar(255) null,
`tags` varchar(1000) null,
request longtext null,
response longtext null,
STATUS VARCHAR(10) null,
create_time bigint(13) null,
update_time bigint(13) null,
create_user_id VARCHAR(64) null,
primary key (id),
INDEX `mock_config_id` (`mock_config_id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;

View File

@ -74,7 +74,8 @@
</ms-tab-button>
<!-- 添加/编辑测试窗口-->
<div v-if="item.type=== 'ADD'" class="ms-api-div">
<ms-api-config :syncTabs="syncTabs" @runTest="runTest" @saveApi="saveApi" @createRootModel="createRootModel" ref="apiConfig"
<ms-api-config :syncTabs="syncTabs" @runTest="runTest" @saveApi="saveApi" @mockConfig="mockConfig"
@createRootModel="createRootModel" ref="apiConfig"
:current-api="item.api"
:project-id="projectId"
:currentProtocol="currentProtocol"
@ -94,15 +95,22 @@
<!-- 测试-->
<div v-else-if="item.type=== 'TEST'" class="ms-api-div">
<ms-run-test-http-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" :project-id="projectId"
<ms-run-test-http-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api"
:project-id="projectId"
@saveAsApi="editApi" @refresh="refresh" v-if="currentProtocol==='HTTP'"/>
<ms-run-test-tcp-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" :project-id="projectId"
<ms-run-test-tcp-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api"
:project-id="projectId"
@saveAsApi="editApi" @refresh="refresh" v-if="currentProtocol==='TCP'"/>
<ms-run-test-sql-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" :project-id="projectId"
<ms-run-test-sql-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api"
:project-id="projectId"
@saveAsApi="editApi" @refresh="refresh" v-if="currentProtocol==='SQL'"/>
<ms-run-test-dubbo-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api" :project-id="projectId"
<ms-run-test-dubbo-page :syncTabs="syncTabs" :currentProtocol="currentProtocol" :api-data="item.api"
:project-id="projectId"
@saveAsApi="editApi" @refresh="refresh" v-if="currentProtocol==='DUBBO'"/>
</div>
<div v-else-if="item.type=== 'MOCK'" class="ms-api-div">
<mock-config :base-mock-config-data="item.mock"></mock-config>
</div>
</el-tab-pane>
<el-tab-pane name="add">
@ -151,6 +159,7 @@
import {getLabel} from "@/common/js/tableUtils";
import {API_CASE_LIST, API_LIST} from "@/common/js/constants";
import MockConfig from "@/business/components/api/definition/components/mock/MockConfig";
export default {
name: "ApiDefinition",
computed: {
@ -185,7 +194,8 @@
MsRunTestTcpPage,
MsRunTestSqlPage,
MsRunTestDubboPage,
ApiDocumentsPage
ApiDocumentsPage,
MockConfig
},
props: {
visible: {
@ -338,6 +348,24 @@
createRootModel() {
this.$refs.nodeTree.createRootModel();
},
handleMockTabsConfig(targetName, action, param) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');
}
let newTabName = getUUID();
this.apiTabs.push({
title: targetName,
name: newTabName,
closable: true,
type: action,
mock: param,
});
this.apiDefaultTab = newTabName;
},
handleTabsEdit(targetName, action, api) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
@ -399,6 +427,9 @@
this.handleTabsEdit(this.$t("commons.api"), "TEST", data);
this.setTabTitle(data);
},
mockConfig(data) {
this.handleMockTabsConfig(this.$t("commons.mock"), "MOCK", data);
},
saveApi(data) {
this.setTabTitle(data);
this.refresh(data);

View File

@ -2,17 +2,26 @@
<div class="card-container">
<!-- HTTP 请求参数 -->
<ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" @createRootModelInTree="createRootModelInTree" :request="request" :response="response"
:basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'HTTP'" ref="httpApi"/>
<ms-edit-complete-http-api @runTest="runTest" @saveApi="saveApi" @createRootModelInTree="createRootModelInTree"
:request="request" :response="response" :project-id="projectId"
@mockConfig="mockConfig"
:basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs"
v-if="currentProtocol === 'HTTP'" ref="httpApi"/>
<!-- TCP -->
<ms-edit-complete-tcp-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'" ref="tcpApi"/>
<ms-edit-complete-tcp-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree"
@saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'"
ref="tcpApi"/>
<!--DUBBO-->
<ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'" ref="dubboApi"/>
<ms-edit-complete-dubbo-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree"
@saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'"
ref="dubboApi"/>
<!--SQL-->
<ms-edit-complete-sql-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree" @saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'" ref="sqlApi"/>
<ms-edit-complete-sql-api :request="request" @runTest="runTest" @createRootModelInTree="createRootModelInTree"
@saveApi="saveApi" :basisData="currentApi"
:moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'"
ref="sqlApi"/>
</div>
</template>
@ -96,7 +105,10 @@ export default {
this.$success(this.$t('commons.save_success'));
this.reqUrl = "/api/definition/update";
this.$emit('runTest', data);
})
});
},
mockConfig(data) {
this.$emit('mockConfig', data);
},
createRootModelInTree() {
this.$emit("createRootModel");

View File

@ -79,10 +79,28 @@
</el-row>
</div>
<!-- MOCK信息 -->
<p class="tip">{{ $t('test_track.plan_view.mock_info') }} </p>
<div class="base-info">
<el-row>
<el-col :span="20">
Mock地址
<el-link>
{{ this.mockBaseUrl + "/mock/" + this.projectId + (this.httpForm.path == null ? "" : this.httpForm.path) }}
</el-link>
</el-col>
<el-col :span="4">
<el-link @click="mockSetting" type="primary">Mock设置</el-link>
</el-col>
</el-row>
</div>
<!-- 请求参数 -->
<div>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<ms-api-request-form :showScript="false" :request="request" :headers="request.headers" :isShowEnable="isShowEnable"/>
<ms-api-request-form :showScript="false" :request="request" :headers="request.headers"
:isShowEnable="isShowEnable"/>
</div>
</el-form>
@ -129,20 +147,21 @@
moduleId: [{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
status: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
},
httpForm: {environmentId: "", tags: []},
httpForm: {environmentId: "", path: "", tags: []},
isShowEnable: true,
maintainerOptions: [],
currentModule: {},
reqOptions: REQ_METHOD,
options: API_STATUS,
mockEnvironment: {},
moduleObj: {
id: 'id',
label: 'name',
},
mockBaseUrl: "",
}
},
props: {moduleOptions: {}, request: {}, response: {}, basisData: {}, syncTabs: Array},
props: {moduleOptions: {}, request: {}, response: {}, basisData: {}, syncTabs: Array, projectId: String},
watch: {
syncTabs() {
if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) {
@ -231,10 +250,34 @@
this.$error(this.$t('api_test.request.url_invalid'), 2000);
}
},
setModule(id,data) {
setModule(id, data) {
this.httpForm.moduleId = id;
this.httpForm.modulePath = data.path;
},
initMockEnvironment() {
let url = "/api/definition/getMockEnvironment/";
this.$get(url + this.projectId, response => {
this.mockEnvironment = response.data;
let httpConfig = JSON.parse(this.mockEnvironment.config);
if (httpConfig != null) {
this.mockBaseUrl = httpConfig.httpConfig.socket;
}
});
},
mockSetting() {
if (this.httpForm.id == null) {
this.$alert(this.$t('api_test.mock.create_error'));
} else {
let mockParam = {};
mockParam.projectId = this.projectId;
mockParam.apiId = this.httpForm.id;
this.$post('/mockConfig/genMockConfig', mockParam, response => {
let mockConfig = response.data;
this.$emit('mockConfig', mockConfig);
});
}
}
},
created() {
@ -243,6 +286,8 @@
this.basisData.environmentId = "";
}
this.httpForm = JSON.parse(JSON.stringify(this.basisData));
this.initMockEnvironment();
}
}
</script>

View File

@ -0,0 +1,376 @@
<template>
<div>
<p class="tip">期望列表</p>
<div class="card">
<el-input :placeholder="$t('commons.search_by_name')" class="search-input" size="small"
clearable="serchInputClearable"
v-model="tableSearch"/>
<el-table ref="table" border
:data="mockConfigData.mockExpectConfigList.filter(data=>!tableSearch || data.name.toLowerCase().includes(tableSearch.toLowerCase()))"
@row-click="clickRow"
row-key="id" class="test-content" :height="screenHeight">
<el-table-column :label="$t('api_test.mock.table.name')" min-width="160px" prop="name"></el-table-column>
<el-table-column :label="$t('api_test.mock.table.tag')" min-width="200px" prop="tags">
<template v-slot:default="scope">
<ms-tag v-for="(itemName,index) in scope.row.tags" :key="index" type="success" effect="plain"
:show-tooltip="true" :content="itemName"
style="margin-left: 0px; margin-right: 2px"/>
</template>
</el-table-column>
<el-table-column :label="$t('api_test.mock.table.creator')" min-width="160px"
prop="createUserId"></el-table-column>
<el-table-column :label="$t('api_test.mock.table.status')" min-width="80px" prop="status">
<template v-slot:default="scope">
<div>
<el-switch
v-model="scope.row.status"
class="captcha-img"
@change="changeStatus(scope.row)"
></el-switch>
</div>
</template>
</el-table-column>
<el-table-column :label="$t('api_test.mock.table.update_time')" min-width="160px" prop="updateTime">
<template v-slot:default="scope">
<span>{{ scope.row.updateTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column fixed="right" min-width="100" align="center" :label="$t('commons.operating')">
<template v-slot:default="scope">
<ms-table-operator-button :tip="$t('commons.copy')" icon="el-icon-copy-document"
@exec="copyExpect(scope.row)"
v-tester/>
<ms-table-operator-button :tip="$t('commons.edit')" icon="el-icon-delete" @exec="removeExpect(scope.row)"
v-tester/>
</template>
</el-table-column>
</el-table>
</div>
<!-- 期望详情 -->
<p class="tip">{{ $t('api_test.mock.expect_detail') }}</p>
<el-form :model="mockExpectConfig" :rules="rule" ref="mockExpectForm" label-width="80px" label-position="right">
<div class="card">
<div class="base-info">
<el-row>
<el-col>{{ $t('api_test.mock.base_info') }}</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input class="ms-http-input" size="small" v-model="mockExpectConfig.name"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('commons.tag')" prop="tag">
<ms-input-tag :currentScenario="mockExpectConfig" v-if="showHeadTable" ref="tag"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>{{ $t('api_test.mock.req_param') }}</el-col>
</el-row>
<el-row>
<el-col style="margin: 10px">
<el-switch v-model="mockExpectConfig.request.jsonParam">
</el-switch>
JSON
</el-col>
</el-row>
<el-row>
<div v-if="mockExpectConfig.request.jsonParam">
<ms-code-edit height="400px" :mode="'json'" ref="codeEdit" :data.sync="mockExpectConfig.request.jsonData"
style="margin-top: 10px;"/>
</div>
<div v-else>
<mock-row-variables :show-copy="false" v-if="showHeadTable" :header-suggestions="apiParams"
:items="mockExpectConfig.request.variables" ref="reqHttpHead"/>
</div>
</el-row>
<el-row style="margin-top: 10px;">
<el-col>{{ $t('api_test.mock.rsp_param') }}</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="HTTP Code" label-width="100px" prop="response.httpCode">
<el-input class="ms-http-input" size="small" v-model="mockExpectConfig.response.httpCode"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="延时 (ms)" prop="response.delayed">
<el-input-number v-model="mockExpectConfig.response.delayed" :min="0">
<template slot="append">ms</template>
</el-input-number>
</el-form-item>
</el-col>
</el-row>
<el-row>
<span style="margin: 10px;font-size: 13px">
HTTP头:
</span>
</el-row>
<el-row>
<mock-row-variables v-if="showHeadTable" :show-copy="false" :header-suggestions="headerSuggestions"
:items="mockExpectConfig.response.httpHeads" ref="rspHttpHead"/>
</el-row>
<el-row style="margin-top: 10px;">
<el-form-item label="Body:" label-width="50px" prop="response.body">
<ms-code-edit height="200px" :mode="'txt'" ref="codeEdit" :data.sync="mockExpectConfig.response.body"
style="margin-top: 10px;"/>
</el-form-item>
</el-row>
<el-row>
<div style="float: right;margin-right: 20px">
<el-button type="primary" size="small" @click="saveMockExpectConfig" title="ctrl + s">{{
$t('commons.add')
}}
</el-button>
<el-button type="primary" size="small" @click="cleanMockExpectConfig">{{
$t('commons.clear')
}}
</el-button>
<el-button type="primary" size="small" v-if="mockExpectConfig.id != '' && mockExpectConfig.id != null"
@click="updateMockExpectConfig">{{ $t('commons.update') }}
</el-button>
</div>
</el-row>
</div>
</div>
</el-form>
</div>
</template>
<script>
import MsTableOperatorButton from "@/business/components/common/components/MsTableOperatorButton";
import MockRowVariables from "@/business/components/api/definition/components/mock/MockRowVariables";
import MsInputTag from "@/business/components/api/automation/scenario/MsInputTag";
import MsCodeEdit from "@/business/components/api/definition/components/MsCodeEdit";
import MsApiVariableAdvance from "@/business/components/api/test/components/ApiVariableAdvance";
import MsTag from "@/business/components/common/components/MsTag";
import {Scenario} from "@/business/components/api/test/model/ScenarioModel";
import {REQUEST_HEADERS} from "@/common/js/constants";
export default {
name: "MockConfig",
components: {
MockRowVariables,
MsTableOperatorButton,
MsInputTag,
MsCodeEdit,
MsApiVariableAdvance,
MsTag,
},
data() {
return {
screenHeight: 300,
tableSearch: "",
showHeadTable: true,
serchInputClearable: true,
mockConfigData: {},
apiParams: [],
headerSuggestions: REQUEST_HEADERS,
mockExpectConfig: {
id: "",
name: "",
mockConfigId: "",
request: {
jsonParam: false,
variables: [],
jsonData: "{}",
},
response: {
httpCode: "",
delayed: "",
httpHeads: [],
body: "",
},
},
rule: {
name: [
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
{max: 100, message: this.$t('test_track.length_less_than') + '100', trigger: 'blur'}
],
response: {
httpCode: [{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},],
delayed: [{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},],
body: [{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},],
},
},
};
},
props: {baseMockConfigData: {},},
created() {
this.mockConfigData = this.baseMockConfigData;
this.searchApiParams(this.mockConfigData.mockConfig.apiId);
},
methods: {
searchApiParams(apiId) {
let selectUrl = "/mockConfig/getApiParams/" + apiId;
this.$get(selectUrl, response => {
this.apiParams = response.data;
});
},
copyExpect(row) {
let selectUrl = "/mockConfig/mockExpectConfig/" + row.id;
this.$get(selectUrl, response => {
let data = response.data;
this.showHeadTable = false;
this.mockExpectConfig = data;
this.mockExpectConfig.id = "";
this.mockExpectConfig.name = this.mockExpectConfig.name + "_copy";
if (this.mockExpectConfig.request == null) {
this.mockExpectConfig.request = {
jsonParam: false,
variables: [],
jsonData: "{}",
};
}
if (this.mockExpectConfig.response == null) {
this.mockExpectConfig.response = {
httpCode: "",
delayed: "",
httpHeads: [],
body: "",
};
}
this.$nextTick(function () {
this.showHeadTable = true;
this.saveMockExpectConfig();
});
});
},
removeExpect(row) {
let mockInfoId = row.mockConfigId;
let selectUrl = "/mockConfig/deleteMockExpectConfig/" + row.id;
this.$get(selectUrl, response => {
this.cleanMockExpectConfig();
this.refreshMockInfo(mockInfoId);
});
},
saveMockExpectConfig() {
let mockConfigId = this.mockConfigData.mockConfig.id;
this.mockExpectConfig.mockConfigId = mockConfigId;
let formCheckResult = this.checkMockExpectForm("mockExpectForm");
this.cleanMockExpectConfig();
},
cleanMockExpectConfig() {
this.showHeadTable = false;
this.mockExpectConfig = {
id: "",
name: "",
mockConfigId: "",
request: {
jsonParam: false,
variables: [],
jsonData: "{}",
},
response: {
httpCode: "",
delayed: "",
httpHeads: [],
body: "",
},
};
this.$nextTick(function () {
this.showHeadTable = true;
});
},
updateMockExpectConfig() {
this.checkMockExpectForm("mockExpectForm");
},
uploadMockExpectConfig() {
let url = "/mockConfig/updateMockExpectConfig";
let param = this.mockExpectConfig;
this.$post(url, param, response => {
let returnData = response.data;
this.mockExpectConfig.id = returnData.id;
this.refreshMockInfo(param.mockConfigId);
});
},
refreshMockInfo(mockConfigId) {
let mockParam = {};
mockParam.id = mockConfigId;
this.$post('/mockConfig/genMockConfig', mockParam, response => {
this.mockConfigData = response.data;
});
},
checkMockExpectForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.uploadMockExpectConfig();
return true;
} else {
return false;
}
});
},
changeStatus(row) {
let mockParam = {};
mockParam.id = row.id;
mockParam.status = row.status;
this.$post('/mockConfig/updateMockExpectConfig', mockParam, response => {
});
},
clickRow(row, column, event) {
let selectUrl = "/mockConfig/mockExpectConfig/" + row.id;
this.$get(selectUrl, response => {
let data = response.data;
this.showHeadTable = false;
this.mockExpectConfig = data;
if (this.mockExpectConfig.request == null) {
this.mockExpectConfig.request = {
jsonParam: false,
variables: [],
jsonData: "{}",
};
}
if (this.mockExpectConfig.response == null) {
this.mockExpectConfig.response = {
httpCode: "",
delayed: "",
httpHeads: [],
body: "",
};
}
this.$nextTick(function () {
this.showHeadTable = true;
});
});
}
}
};
</script>
<style scoped>
.tip {
padding: 3px 5px;
font-size: 16px;
border-radius: 4px;
border-left: 4px solid #783887;
margin: 20px 0;
}
.search-input {
float: right;
width: 300px;
margin-right: 10px;
margin-bottom: 10px;
}
.base-info .el-form-item {
width: 100%;
}
.base-info .el-form-item >>> .el-form-item__content {
width: 80%;
}
.base-info .ms-http-select {
width: 100%;
}
</style>

View File

@ -0,0 +1,119 @@
<template>
<div>
<span class="kv-description" v-if="description">
{{ description }}
</span>
<div class="kv-row" v-for="(item, index) in items" :key="index">
<el-row type="flex" :gutter="20" justify="space-between" align="middle">
<el-col class="kv-checkbox">
<input type="checkbox" v-if="!isDisable(index)" @change="change" :value="item.uuid" v-model="item.enable"
:disabled="isDisable(index) || isReadOnly"/>
</el-col>
<el-col>
<el-autocomplete :disabled="isReadOnly" :maxlength="400" v-model="item.name" size="small" style="width: 100%"
:fetch-suggestions="querySearch"
show-word-limit/>
<!-- <ms-api-variable-input :show-copy="showCopy" :show-variable="showVariable" :is-read-only="isReadOnly" v-model="item.name" size="small" maxlength="200" @change="change"-->
<!-- :placeholder="$t('api_test.variable_name')" show-word-limit/>-->
</el-col>
<el-col>
<el-input :disabled="isReadOnly" v-model="item.value" size="small" @change="change"
:placeholder="$t('api_test.value')" show-word-limit/>
</el-col>
<el-col class="kv-delete">
<el-button size="mini" class="el-icon-delete-solid" circle @click="remove(index)"
:disabled="isDisable(index) || isReadOnly"/>
</el-col>
</el-row>
</div>
</div>
</template>
<script>
import {KeyValue} from "@/business/components/api/test/model/ScenarioModel";
import MsApiVariableInput from "@/business/components/api/test/components/ApiVariableInput";
export default {
name: "MsApiScenarioVariables",
components: {MsApiVariableInput},
props: {
description: String,
items: Array,
isReadOnly: {
type: Boolean,
default: false
},
showVariable: {
type: Boolean,
default: true
},
showCopy: {
type: Boolean,
default: true
},
headerSuggestions: Array
},
data() {
return {};
},
methods: {
remove: function (index) {
this.items.splice(index, 1);
this.$emit('change', this.items);
},
change: function () {
let isNeedCreate = true;
let removeIndex = -1;
this.items.forEach((item, index) => {
if (!item.name && !item.value) {
//
if (index !== this.items.length - 1) {
removeIndex = index;
}
//
isNeedCreate = false;
}
});
if (isNeedCreate) {
this.items.push(new KeyValue({enable: true}));
}
this.$emit('change', this.items);
// TODO key
},
isDisable: function (index) {
return this.items.length - 1 === index;
},
querySearch(queryString, cb) {
let suggestions = this.headerSuggestions;
let results = queryString ? suggestions.filter(this.createFilter(queryString)) : suggestions;
cb(results);
},
},
created() {
if (this.items.length === 0) {
this.items.push(new KeyValue({enable: true}));
}
}
};
</script>
<style scoped>
.kv-description {
font-size: 13px;
}
.kv-checkbox {
width: 20px;
margin-right: 10px;
}
.kv-row {
margin-top: 10px;
}
.kv-delete {
width: 60px;
}
</style>

View File

@ -80,7 +80,7 @@
},
isDisable: function (index) {
return this.items.length - 1 === index;
}
},
},
created() {

View File

@ -148,6 +148,7 @@ export default {
tag_tip: "Enter Enter to Add Label",
node_name_tip: "The name cannot contain'\\'",
more_operator: "More operator",
mock: "Mock settings",
table: {
select_tip: "Item {0} data is selected"
},
@ -586,6 +587,20 @@ export default {
select_all_data: "Select all datas({0})",
select_show_data: "Select show datas({0})",
},
mock: {
create_error: "Api info is not saved",
table: {
name: "Name",
tag: "Tag",
creator: "Creator",
status: "Status",
update_time: "Update time"
},
expect_detail: "Expect",
base_info: "Base info",
req_param: "Request params",
rsp_param: "Response Params",
},
definition: {
api_title: "Api test",
case_title: "Test Case",
@ -1404,6 +1419,7 @@ export default {
operate_step: "Operate step",
edit_component: "Edit component",
base_info: "Base info",
mock_info: "Mock info",
test_result: "Test result",
result_distribution: "Result distribution",
custom_component: "Custom",

View File

@ -149,6 +149,7 @@ export default {
tag_tip: "输入回车添加标签",
node_name_tip: "名称不能包含'\\'",
more_operator: "更多操作",
mock: "Mock 设置",
table: {
select_tip: "已选中 {0} 条数据"
},
@ -595,6 +596,20 @@ export default {
select_all_data: "选择所有数据(共{0}条)",
select_show_data: "选择可见数据(共{0}条)",
},
mock: {
create_error: "接口信息未保存",
table: {
name: "期望名称",
tag: "标签",
creator: "创建人",
status: "状态",
update_time: "更新时间"
},
expect_detail: "期望详情",
base_info: "基本信息",
req_param: "请求参数",
rsp_param: "响应内容",
},
definition: {
api_title: "接口列表",
case_title: "用例列表",
@ -1418,6 +1433,7 @@ export default {
operate_step: "操作步骤",
edit_component: "编辑组件",
base_info: "基础信息",
mock_info: "Mock信息",
test_result: "测试结果",
result_distribution: "测试结果分布",
custom_component: "自定义模块",

View File

@ -149,6 +149,7 @@ export default {
tag_tip: "輸入回車添加標簽",
node_name_tip: "名稱不能包含'\\'",
more_operator: "更多操作",
mock: "Mock 設置",
table: {
select_tip: "已选中 {0} 条数据"
},
@ -585,6 +586,20 @@ export default {
select_all_data: "選擇所有數據(共{0}條)",
select_show_data: "選擇可見數據(共{0}條)",
},
mock: {
create_error: "接口信息未保存",
table: {
name: "期望名稱",
tag: "標籤",
creator: "創建人",
status: "狀態",
update_time: "更新時間"
},
expect_detail: "期望詳情",
base_info: "基本信息",
req_param: "請求參賽",
rsp_param: "響應內容",
},
definition: {
api_title: "接口列表",
case_title: "用例列表",
@ -1406,6 +1421,7 @@ export default {
operate_step: "操作步驟",
edit_component: "編輯組件",
base_info: "基礎信息",
mock_info: "Mock信息",
test_result: "測試結果",
result_distribution: "測試結果分布",
custom_component: "自定義模塊",