📄 htmltestcreator.java
字号:
package xyz.frame.plugin;import java.util.Map;import org.apache.log4j.Logger;import xyz.frame.LogicRequest;/** * A creator which uses the client outputstream to show the test result. * * @author Guilherme Silveira */public class HtmlTestCreator implements TestCreator { private static final Logger logger = Logger .getLogger(HtmlTestCreator.class); protected static final String CREATOR_ID = HtmlTestCreator.class + "_ID"; public void execute(Object component, LogicRequest request, String result) { StringBuilder buffer = new StringBuilder(); buffer.append("<html>\n<div id=\"test\"><pre>\n"); buffer.append("\n"); buffer.append("TestSession session = ENGINE.createSession();\n"); buffer.append(String.format( "Result result = session.execute(\"%s.%s.logic\"", request .getComponentName(), request.getLogicName())); Map<String, Object> parameters = request.getRequestContext() .getParameterMap(); for (String param : parameters.keySet()) { buffer.append(appendParameter(param, parameters.get(param))); } buffer.append(");\n"); buffer.append(String.format( "assert result.getReturnCode().equals(\"%s\");\n", result)); buffer.append("</pre></div>\n"); logger.debug(buffer.toString()); request.getRequestContext().setAttribute(CREATOR_ID, buffer.toString()); } private String appendParameter(String param, Object object) { if (object.getClass().isArray()) { String[] values = (String[]) object; String result = ""; for (String value : values) { result += appendParameter(param, value); } return result; } else { return ",\n\t\"" + param + "=" + object.toString() + "\""; } } public boolean shouldRedirect() { return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -