From 864b9124ac91e0cb10e1be4ca34dcda004bd1658 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 23 Nov 2023 17:49:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0mock=E5=87=BD=E6=95=B0=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/controller/ApiTestController.java | 8 ++++++++ .../api/controller/ApiTestControllerTests.java | 7 +++++++ pom.xml | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java index 99ea236386..f45be2bdff 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java @@ -1,6 +1,7 @@ package io.metersphere.api.controller; import io.metersphere.api.service.ApiTestService; +import io.metersphere.jmeter.mock.Mock; import io.metersphere.system.dto.ProtocolDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -29,4 +30,11 @@ public class ApiTestController { public List getProtocols(@PathVariable String organizationId) { return apiTestService.getProtocols(organizationId); } + + + @GetMapping("/mock/{key}") + @Operation(summary = "获取mock数据") + public String mock(@PathVariable String key) { + return Mock.calculate(key).toString(); + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java index c1dfd3c4ff..ebcb5dfc72 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java @@ -18,6 +18,7 @@ public class ApiTestControllerTests extends BaseTest { private static final String BASE_PATH = "/api/test/"; protected static final String PROTOCOL_LIST = "protocol/{0}"; + protected static final String MOCK = "mock/{0}"; @Override protected String getBasePath() { @@ -29,4 +30,10 @@ public class ApiTestControllerTests extends BaseTest { // @@请求成功 this.requestGetWithOk(PROTOCOL_LIST, this.DEFAULT_ORGANIZATION_ID).andReturn(); } + + @Test + public void getMock() throws Exception { + // @@请求成功 + this.requestGetWithOk(MOCK, "@integer").andReturn(); + } } diff --git a/pom.xml b/pom.xml index f07bd0c583..de162285ae 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 2.1.4 32.0.1-jre 6.0.0 - 1.5 + 3.0 1.0.7 3.23.5 5.1.0