feat(接口测试): 添加mock函数预览

This commit is contained in:
fit2-zhao 2023-11-23 17:49:48 +08:00 committed by Craftsman
parent af3ef24316
commit 864b9124ac
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import io.metersphere.api.service.ApiTestService; import io.metersphere.api.service.ApiTestService;
import io.metersphere.jmeter.mock.Mock;
import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.dto.ProtocolDTO;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -29,4 +30,11 @@ public class ApiTestController {
public List<ProtocolDTO> getProtocols(@PathVariable String organizationId) { public List<ProtocolDTO> getProtocols(@PathVariable String organizationId) {
return apiTestService.getProtocols(organizationId); return apiTestService.getProtocols(organizationId);
} }
@GetMapping("/mock/{key}")
@Operation(summary = "获取mock数据")
public String mock(@PathVariable String key) {
return Mock.calculate(key).toString();
}
} }

View File

@ -18,6 +18,7 @@ public class ApiTestControllerTests extends BaseTest {
private static final String BASE_PATH = "/api/test/"; private static final String BASE_PATH = "/api/test/";
protected static final String PROTOCOL_LIST = "protocol/{0}"; protected static final String PROTOCOL_LIST = "protocol/{0}";
protected static final String MOCK = "mock/{0}";
@Override @Override
protected String getBasePath() { protected String getBasePath() {
@ -29,4 +30,10 @@ public class ApiTestControllerTests extends BaseTest {
// @@请求成功 // @@请求成功
this.requestGetWithOk(PROTOCOL_LIST, this.DEFAULT_ORGANIZATION_ID).andReturn(); this.requestGetWithOk(PROTOCOL_LIST, this.DEFAULT_ORGANIZATION_ID).andReturn();
} }
@Test
public void getMock() throws Exception {
// @@请求成功
this.requestGetWithOk(MOCK, "@integer").andReturn();
}
} }

View File

@ -27,7 +27,7 @@
<dom4j.version>2.1.4</dom4j.version> <dom4j.version>2.1.4</dom4j.version>
<guava.version>32.0.1-jre</guava.version> <guava.version>32.0.1-jre</guava.version>
<pagehelper.version>6.0.0</pagehelper.version> <pagehelper.version>6.0.0</pagehelper.version>
<metersphere-jmeter-functions.version>1.5</metersphere-jmeter-functions.version> <metersphere-jmeter-functions.version>3.0</metersphere-jmeter-functions.version>
<quartz-starter.version>1.0.7</quartz-starter.version> <quartz-starter.version>1.0.7</quartz-starter.version>
<redisson-starter.version>3.23.5</redisson-starter.version> <redisson-starter.version>3.23.5</redisson-starter.version>
<guice.version>5.1.0</guice.version> <guice.version>5.1.0</guice.version>