From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001
From: lee <4766465@qq.com>
Date: Wed, 18 Dec 2024 13:27:00 +0800
Subject: [PATCH] init

---
 system-test/src/main/java/com/yami/shop/systemtest/util/CheckUtil.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/system-test/src/main/java/com/yami/shop/systemtest/util/CheckUtil.java b/system-test/src/main/java/com/yami/shop/systemtest/util/CheckUtil.java
new file mode 100644
index 0000000..0ed47e6
--- /dev/null
+++ b/system-test/src/main/java/com/yami/shop/systemtest/util/CheckUtil.java
@@ -0,0 +1,50 @@
+package com.yami.shop.systemtest.util;
+
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.yami.shop.common.response.ServerResponseEntity;
+import com.yami.shop.common.util.Json;
+
+import java.util.List;
+
+public class CheckUtil {
+
+
+
+
+    public static void check(HttpResponse response) {
+        String body = getBody(response);
+        ServerResponseEntity serverResponseEntity = Json.parseObject(body, ServerResponseEntity.class);
+        if (!serverResponseEntity.isSuccess()) {
+            throw new RuntimeException(serverResponseEntity.getMsg());
+        }
+    }
+
+    public static <T>  T checkAndGetObject(HttpResponse response, Class<T> clazz) {
+        String body = getBody(response);
+        TypeReference<ServerResponseEntity<T>> typeReference = new TypeReference<ServerResponseEntity<T>>(clazz) {};
+        ServerResponseEntity<T> serverResponseEntity = JSON.parseObject(body, typeReference);
+        if (!serverResponseEntity.isSuccess()) {
+            throw new RuntimeException(serverResponseEntity.getMsg());
+        }
+        return serverResponseEntity.getData();
+    }
+
+    public static <T> List<T> checkAndGetArray(HttpResponse response, Class<T[]> clazz) {
+        String body = getBody(response);
+        ServerResponseEntity<T> serverResponseEntity = Json.parseObject(body, ServerResponseEntity.class);
+        if (!serverResponseEntity.isSuccess()) {
+            throw new RuntimeException(serverResponseEntity.getMsg());
+        }
+        return Json.parseArray(Json.toJsonString(serverResponseEntity.getData()), clazz);
+    }
+
+    private static String getBody(HttpResponse response){
+        if (!response.isOk()) {
+            throw new RuntimeException("请求异常");
+        }
+        System.out.println(response.body());
+        return response.body();
+    }
+}

--
Gitblit v1.9.3