|
@@ -0,0 +1,63 @@
|
|
|
|
|
+package cn.seecoder.core.pipeline.handler;
|
|
|
|
|
+
|
|
|
|
|
+import cn.seecoder.common.util.SpringUtil;
|
|
|
|
|
+import cn.seecoder.core.pipeline.Context;
|
|
|
|
|
+import cn.seecoder.core.pipeline.PipelineException;
|
|
|
|
|
+import cn.seecoder.web.service.APITest.APITestService;
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
+import lombok.Data;
|
|
|
|
|
+import lombok.EqualsAndHashCode;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static cn.seecoder.core.pipeline.PipelineException.API_TEST_ID_RESOLVE_ERROR;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author PuHong Weng
|
|
|
|
|
+ * @date 2021/4/21
|
|
|
|
|
+ * @description:
|
|
|
|
|
+ * devcloud 构建时自动调取设定好的api测试执行测试
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Data
|
|
|
|
|
+@EqualsAndHashCode(callSuper = false)
|
|
|
|
|
+public class ApiTestHandler extends AbstractHandler {
|
|
|
|
|
+
|
|
|
|
|
+ private final APITestService apiTestService;
|
|
|
|
|
+
|
|
|
|
|
+ public ApiTestHandler() {
|
|
|
|
|
+ this.apiTestService = SpringUtil.getBean(APITestService.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 要自动执行的apiTest的json
|
|
|
|
|
+ * 格式 [1,2,3]
|
|
|
|
|
+ */
|
|
|
|
|
+ private String apiTestId;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void process(Context context) throws PipelineException {
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
+ List<Integer> apiTestIds;
|
|
|
|
|
+ try {
|
|
|
|
|
+ apiTestIds = objectMapper.readValue(apiTestId, new TypeReference<List<Integer>>() {
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
|
|
+ throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE,API_TEST_ID_RESOLVE_ERROR,e);
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Integer testId : apiTestIds){
|
|
|
|
|
+ try {
|
|
|
|
|
+ apiTestService.executeAPITest(testId);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ log.warn("api test 出现 InterruptedException, 目前暂无特殊处理。 Test id: {}",testId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|