feat(接口测试): 定义导入处理结构
This commit is contained in:
parent
87c905e46b
commit
094a594986
|
@ -0,0 +1,10 @@
|
|||
package io.metersphere.api.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ExportRequest {
|
||||
private String id;
|
||||
|
||||
// TODO: Add more fields
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package io.metersphere.api.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ImportRequest {
|
||||
private String id;
|
||||
private String name;
|
||||
private String moduleId;
|
||||
private String environmentId;
|
||||
private String projectId;
|
||||
private String platform;
|
||||
private String swaggerUrl;
|
||||
|
||||
//导入策略
|
||||
private String modeId;
|
||||
private String userId;
|
||||
private String versionId; // 新导入选择的版本
|
||||
private String updateVersionId; // 覆盖导入已存在的接口选择的版本
|
||||
private String defaultVersion;
|
||||
//调用类型
|
||||
private String type;
|
||||
// 是否开启自定义ID
|
||||
private Boolean openCustomNum = false;
|
||||
// 是否覆盖模块
|
||||
private Boolean coverModule;
|
||||
// 当前协议
|
||||
private String protocol;
|
||||
//上传文件来源,目前用于辨别是否是idea插件
|
||||
private String origin;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package io.metersphere.api.enums;
|
||||
|
||||
public enum ApiImportPlatform {
|
||||
MeterSphere, Postman, Swagger3, Plugin, Jmeter, Har
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package io.metersphere.api.parser;
|
||||
|
||||
import io.metersphere.api.dto.request.ExportRequest;
|
||||
|
||||
public interface ExportParser<T> {
|
||||
T parse(ExportRequest request) throws Exception;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package io.metersphere.api.parser;
|
||||
|
||||
|
||||
import io.metersphere.api.dto.request.ImportRequest;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public interface ImportParser<T> {
|
||||
T parse(InputStream source, ImportRequest request) throws Exception;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package io.metersphere.api.parser;
|
||||
|
||||
import io.metersphere.api.enums.ApiImportPlatform;
|
||||
import io.metersphere.api.parser.api.PostmanParser;
|
||||
import io.metersphere.api.parser.api.Swagger3Parser;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ImportParserFactory {
|
||||
public static ImportParser<?> getImportParser(String platform) {
|
||||
if (StringUtils.equals(ApiImportPlatform.Swagger3.name(), platform)) {
|
||||
return new Swagger3Parser<>();
|
||||
} else if (StringUtils.equals(ApiImportPlatform.Postman.name(), platform)) {
|
||||
return new PostmanParser<>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package io.metersphere.api.parser.api;
|
||||
|
||||
|
||||
import io.metersphere.api.dto.request.ImportRequest;
|
||||
import io.metersphere.api.parser.ImportParser;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class PostmanParser<T> implements ImportParser<T> {
|
||||
|
||||
@Override
|
||||
public T parse(InputStream source, ImportRequest request) {
|
||||
LogUtils.info("PostmanParser parse");
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package io.metersphere.api.parser.api;
|
||||
|
||||
import io.metersphere.api.dto.request.ImportRequest;
|
||||
import io.metersphere.api.parser.ImportParser;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
public class Swagger3Parser<T> implements ImportParser<T> {
|
||||
|
||||
@Override
|
||||
public T parse(InputStream source, ImportRequest request) throws Exception {
|
||||
LogUtils.info("Swagger3Parser parse");
|
||||
|
||||
// todo: 检查swagger文件版本
|
||||
|
||||
// todo:检查文件的合规性
|
||||
|
||||
// todo:解析文件pojo
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package io.metersphere.api.parser;
|
||||
|
||||
import io.metersphere.api.enums.ApiImportPlatform;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@AutoConfigureMockMvc
|
||||
public class ParserTests {
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testImportParserSwagger() throws Exception {
|
||||
Objects.requireNonNull(ImportParserFactory.getImportParser(ApiImportPlatform.Swagger3.name())).parse(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
public void testImportParserPostman() throws Exception {
|
||||
Objects.requireNonNull(ImportParserFactory.getImportParser(ApiImportPlatform.Postman.name())).parse(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testImportParserMs() throws Exception {
|
||||
ImportParserFactory.getImportParser(ApiImportPlatform.MeterSphere.name());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue