refactor(接口测试): 优化获取插件表单选项方法

This commit is contained in:
AgAngle 2024-02-06 15:55:44 +08:00 committed by Craftsman
parent 01a375210e
commit fd13deefc8
2 changed files with 19 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import io.metersphere.plugin.sdk.spi.AbstractMsPlugin;
import io.metersphere.plugin.sdk.util.MSPluginException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
/**
@ -13,14 +14,22 @@ import java.util.List;
*/
public abstract class AbstractApiPlugin extends AbstractMsPlugin {
public List<ApiPluginSelectOption> getPluginOptions(ApiPluginOptionsRequest request) {
String method = request.getOptionMethod();
/**
* 获取插件选项
*
* @param request 请求参数
* @return 选项列表
*/
public List<ApiPluginSelectOption> getPluginOptions(ApiPluginOptionsRequest request) {
try {
// 这里反射调用插件方法获取下拉框选项
return (List<ApiPluginSelectOption>) this.getClass().getMethod(method, request.getClass()).invoke(this, request);
Method method = this.getClass().getMethod(request.getOptionMethod(), request.getClass());
@SuppressWarnings("unchecked")
List<ApiPluginSelectOption> result = (List<ApiPluginSelectOption>) method.invoke(this, request);
return result;
} catch (InvocationTargetException e) {
throw new MSPluginException(e.getTargetException());
} catch (Exception e) {
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new MSPluginException(e);
}
}

View File

@ -8,6 +8,7 @@ import io.metersphere.plugin.sdk.util.PluginUtils;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
public abstract class AbstractPlatform implements Platform {
@ -35,13 +36,15 @@ public abstract class AbstractPlatform implements Platform {
@Override
public List<SelectOption> getPluginOptions(PluginOptionsRequest request) {
String method = request.getOptionMethod();
try {
// 这里反射调用 getIssueTypes 等方法获取下拉框选项
return (List<SelectOption>) this.getClass().getMethod(method, request.getClass()).invoke(this, request);
Method method = this.getClass().getMethod(request.getOptionMethod(), request.getClass());
@SuppressWarnings("unchecked")
List<SelectOption> result = (List<SelectOption>) method.invoke(this, request);
return result;
} catch (InvocationTargetException e) {
throw new MSPluginException(e.getTargetException());
} catch (Exception e) {
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new MSPluginException(e);
}
}