use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.
the class RequestHandlerImplementerTest method implementOneFailed.
@Test
public void implementOneFailed() throws Exception {
// given
ControllerProxy controller = new ControllerProxy(new Controller());
RequestHandlerMethod handlerMethod = new RequestHandlerMethod("/", new EzyMethod(Controller.class.getDeclaredMethod("doGet")));
RequestHandlerImplementer sut = new RequestHandlerImplementer(controller, handlerMethod);
// when
Throwable e = Asserts.assertThrows(sut::implement);
// then
Asserts.assertEquals(0, handlerMethod.getParameterTypes().length);
Asserts.assertThat(e).isEqualsType(IllegalStateException.class);
}
use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.
the class RequestHandlerMethodTest method isPaymentAndFeatureTest.
@Test
public void isPaymentAndFeatureTest() throws Exception {
// given
RequestHandlerMethod sut = new RequestHandlerMethod("/get", new EzyMethod(InternalController.class.getDeclaredMethod("buySomething")));
// when
// then
Asserts.assertTrue(sut.isPayment());
Asserts.assertEquals(sut.getFeature(), "hello.world");
}
use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.
the class ControllerProxy method fetchRequestHandlerMethods.
protected List<RequestHandlerMethod> fetchRequestHandlerMethods() {
List<RequestHandlerMethod> list = new ArrayList<>();
List<EzyMethod> methods = clazz.getPublicMethods(this::isRequestHandlerMethod);
for (EzyMethod method : methods) {
RequestHandlerMethod m = new RequestHandlerMethod(requestURI, method);
list.add(m);
}
return list;
}
use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.
the class EzyRequestControllerProxy method fetchRequestHandlerMethods.
protected List<EzyRequestHandlerMethod> fetchRequestHandlerMethods() {
List<EzyRequestHandlerMethod> list = new ArrayList<>();
List<EzyMethod> methods = clazz.getPublicMethods(this::isRequestHandlerMethod);
for (EzyMethod method : methods) {
EzyRequestHandlerMethod m = new EzyRequestHandlerMethod(commandGroup, method);
list.add(m);
}
return list;
}
use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.
the class EzyRequestHandlerImplementer method makeHandleExceptionMethodContent.
protected String makeHandleExceptionMethodContent() {
EzyMethod method = getHandleExceptionMethod();
EzyFunction function = new EzyFunction(method).throwsException();
EzyBody body = function.body();
Map<Class<?>, EzyExceptionHandlerMethod> exceptionHandlerMethodMap = controller.getExceptionHandlerMethodMap();
Set<Class<?>> exceptionClasses = exceptionHandlerMethodMap.keySet();
EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
for (Class<?> exceptionClass : exceptionTree.toList()) {
EzyExceptionHandlerMethod m = exceptionHandlerMethodMap.get(exceptionClass);
EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if(arg3 instanceof ").append(exceptionClass.getName()).append(") {");
body.append(instructionIf);
EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
instructionHandle.append("this.controller.").append(m.getName()).bracketopen();
appendHandleExceptionMethodArguments(m, instructionHandle, exceptionClass);
instructionHandle.bracketclose();
body.append(instructionHandle);
body.append(new EzyInstruction("\t", "\n", false).append("}"));
}
if (exceptionClasses.size() > 0) {
body.append(new EzyInstruction("\t", "\n", false).append("else {"));
body.append(new EzyInstruction("\t\t", "\n").append("throw arg3"));
body.append(new EzyInstruction("\t", "\n", false).append("}"));
} else {
body.append(new EzyInstruction("\t", "\n").append("throw arg3"));
}
return function.toString();
}
Aggregations