use of core.framework.web.Interceptor in project core-ng-project by neowu.
the class InvocationImpl method proceed.
@Override
public Response proceed() throws Exception {
if (controller.skipInterceptor || currentStack >= interceptors.interceptors.size()) {
logger.debug("execute controller, controller={}", controller.controllerInfo);
return controller.controller.execute(request);
} else {
Interceptor interceptor = interceptors.interceptors.get(currentStack);
currentStack++;
logger.debug("intercept, interceptorClass={}", interceptor.getClass().getCanonicalName());
return interceptor.intercept(this);
}
}
use of core.framework.web.Interceptor in project core-ng-project by neowu.
the class InvocationImplTest method process.
@Test
void process() throws Exception {
Stack stack = new Stack();
TestController controller = new TestController(stack, 3);
Interceptors interceptors = new Interceptors();
interceptors.add(new TestInterceptor(stack, 0));
interceptors.add(new TestInterceptor(stack, 1));
interceptors.add(new TestInterceptor(stack, 2));
InvocationImpl invocation = new InvocationImpl(new ControllerHolder(controller, null, null, null, false), interceptors, mock(Request.class), new WebContextImpl());
Response response = invocation.proceed();
assertEquals(HTTPStatus.NO_CONTENT, response.status());
assertTrue(controller.executed);
for (Interceptor interceptor : interceptors.interceptors) {
assertTrue(((TestInterceptor) interceptor).executed);
}
}
use of core.framework.web.Interceptor in project core-ng-project by neowu.
the class InvocationImplTest method skipInterceptor.
@Test
void skipInterceptor() throws Exception {
Stack stack = new Stack();
TestController controller = new TestController(stack, 0);
Interceptors interceptors = new Interceptors();
interceptors.add(new TestInterceptor(stack, 0));
InvocationImpl invocation = new InvocationImpl(new ControllerHolder(controller, null, null, null, true), interceptors, mock(Request.class), new WebContextImpl());
Response response = invocation.proceed();
assertEquals(HTTPStatus.NO_CONTENT, response.status());
assertTrue(controller.executed);
for (Interceptor interceptor : interceptors.interceptors) {
assertFalse(((TestInterceptor) interceptor).executed);
}
}
Aggregations