refactor(接口测试): 优化获取插件表单选项方法
This commit is contained in:
parent
01a375210e
commit
fd13deefc8
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 获取插件选项
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @return 选项列表
|
||||
*/
|
||||
public List<ApiPluginSelectOption> getPluginOptions(ApiPluginOptionsRequest request) {
|
||||
String method = request.getOptionMethod();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue