From 9312246003eb231c51b4879ea2d7aacda2c50291 Mon Sep 17 00:00:00 2001 From: MeterSphere Bot <78466014+metersphere-bot@users.noreply.github.com> Date: Thu, 1 Sep 2022 13:59:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Djsonschema=E9=80=89=E6=8B=A9=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E8=BF=90=E8=A1=8C=E6=B2=A1=E6=9C=89=E7=94=9F=E6=95=88?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7=20(#17612)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016488 --user=王孝刚 【接口测试】github #17514,场景中使用枚举,执行接口,请求内容未使用枚举值 https://www.tapd.cn/55049933/s/1236649 Co-authored-by: wxg0103 <727495428@qq.com> --- .../io/metersphere/commons/json/JSONSchemaRunTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaRunTest.java b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaRunTest.java index 31a1b591a9..43670ad2f8 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaRunTest.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaRunTest.java @@ -2,7 +2,9 @@ package io.metersphere.commons.json; import com.alibaba.fastjson.JSONObject; import com.google.gson.*; +import io.metersphere.commons.utils.EnumPropertyUtil; import io.metersphere.jmeter.utils.ScriptEngineUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.util.NumberUtils; @@ -248,6 +250,12 @@ public class JSONSchemaRunTest { if (isMock(object)) { String value = ScriptEngineUtils.buildFunctionCallString(object.get(BasicConstant.MOCK).getAsJsonObject().get(BasicConstant.MOCK).getAsString()); return value; + } else if (object.has(BasicConstant.ENUM)) { + List list = EnumPropertyUtil.analyzeEnumProperty(object); + if (CollectionUtils.isNotEmpty(list)) { + int index = (int) (Math.random() * list.size()); + return list.get(index); + } } } catch (Exception e) { return object.get(BasicConstant.MOCK).getAsJsonObject().get(BasicConstant.MOCK);