Skip to content

Commit

Permalink
单元测试:引入 UnitAuto-机器学习零代码单元测试 库
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Nov 1, 2020
1 parent 5683b20 commit 102e2e3
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 1,010 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
</attributes>
</classpathentry>
<classpathentry kind="lib" path="libs/apijson-orm-4.2.3.jar"/>
<classpathentry kind="lib" path="libs/unitauto-2.5.0.jar"/>
<classpathentry kind="lib" path="libs/unitauto-jar-2.5.0.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Binary file added libs/unitauto-2.5.0.jar
Binary file not shown.
Binary file added libs/unitauto-jar-2.5.0.jar
Binary file not shown.
46 changes: 42 additions & 4 deletions src/main/java/apijson/framework/APIJSONController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
import static apijson.framework.APIJSONConstant.VISITOR_;
import static apijson.framework.APIJSONConstant.VISITOR_ID;

import java.lang.reflect.Method;
import java.rmi.ServerException;

import javax.servlet.AsyncContext;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;
Expand All @@ -42,9 +46,11 @@
import apijson.StringUtil;
import apijson.orm.Parser;
import apijson.orm.Visitor;
import unitauto.MethodUtil;
import unitauto.MethodUtil.InterfaceProxy;


/**request controller
/**APIJSON base controller,建议在子项目被 @RestController 注解的类继承它或通过它的实例调用相关方法
* <br > 全通过 HTTP POST 来请求:
* <br > 1.减少代码 - 客户端无需写 HTTP GET, HTTP PUT 等各种方式的请求代码
* <br > 2.提高性能 - 无需 URL encode 和 decode
Expand Down Expand Up @@ -223,12 +229,44 @@ public Object logout(@NotNull HttpSession session) {
}


public JSONObject invokeMethod(String request) {
return MethodUtil.invokeMethod(request);
}

public JSONObject listMethod(String request) {
return MethodUtil.listMethod(request);
}

public void invokeMethod(String request, HttpServletRequest servletRequest) {
AsyncContext asyncContext = servletRequest.startAsync();

MethodUtil.Listener<JSONObject> listener = new MethodUtil.Listener<JSONObject>() {

@Override
public void complete(JSONObject data, Method method, InterfaceProxy proxy, Object... extras) throws Exception {
ServletResponse servletResponse = asyncContext.getResponse();
if (servletResponse.isCommitted()) {
Log.w(TAG, "invokeMethod listener.complete servletResponse.isCommitted() >> return;");
return;
}

servletResponse.setCharacterEncoding(servletRequest.getCharacterEncoding());
servletResponse.setContentType(servletRequest.getContentType());
servletResponse.getWriter().println(data);
asyncContext.complete();
}
};

try {
MethodUtil.invokeMethod(request, null, listener);
}
catch (Exception e) {
Log.e(TAG, "invokeMethod try { JSONObject req = JSON.parseObject(request); ... } catch (Exception e) { \n" + e.getMessage());
try {
listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(e));
}
catch (Exception e1) {
e1.printStackTrace();
asyncContext.complete();
}
}
}

}
Loading

0 comments on commit 102e2e3

Please sign in to comment.