/** * Maps a DELETE path. */ public ActionBuilder delete(final String path) { return new ActionBuilder().path(path).httpMethod("DELETE"); } /**
/** * Defines HTTP method name and action path. * @see #path(String) */ public ActionBuilder path(final String method, final String path) { this.method = method; return path(path); }
public AutomagicMadvocConfigurator(final ClassScanner classScanner) { actionClassSuffix = "Action"; this.classScanner = classScanner; registerAsConsumer(classScanner); }
@Test void testFiltersPassAndInterceptorsStop3() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterPass(1), new FilterPass(2)), arr(new InterceptorPass(1), new InterceptorStop(), new InterceptorPass(3)) ); actionRequest.invoke(); assertEquals("-F1-F2-I1-x-i1-R-f2-f1", actionRequest.data); }
@Override public Object intercept(ActionRequest actionRequest) throws Exception { ((MyActionRequest)actionRequest).data += "-I"+i; Object result = actionRequest.invoke(); ((MyActionRequest)actionRequest).data += "-i"+i; return result; } }
/** * Throws an exception, as stack can not be invoked. */ @Override public Object apply(final ActionRequest actionRequest) { throw new MadvocException("Wrapper stack can not be invoked"); }
/** * Stops Madvoc. */ @Override public void contextDestroyed(final ServletContextEvent servletContextEvent) { madvoc.stopWebApplication(); }
@Override protected Object invokeActionMethod() throws Exception { data += "-A"; return super.invokeActionMethod(); } }
/** * Invokes the action and returns action result value object. * Invokes all interceptors before and after action invocation. */ public Object invoke() throws Exception { return executionArray[executionIndex++].apply(this); }
/** * Starts with action registration i.e. route binding. */ public ActionBuilder route() { return new ActionBuilder(); }
@Test void testFiltersStopAndInterceptorsPass2() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterPass(1), new FilterStop()), arr(new InterceptorPass(1), new InterceptorPass(2)) ); actionRequest.invoke(); assertEquals("-F1-X-f1", actionRequest.data); }
/** * Maps a GET path. */ public ActionBuilder get(final String path) { return new ActionBuilder().path(path).httpMethod("GET"); } /**
@Override public Object filter(ActionRequest actionRequest) throws Exception { ((MyActionRequest)actionRequest).data += "-F" + i; Object result = actionRequest.invoke(); ((MyActionRequest)actionRequest).data += "-f" + i; return result; } }
@Test void testFiltersStopAndInterceptorsPass1() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterStop(), new FilterPass(2)), arr(new InterceptorPass(1), new InterceptorPass(2)) ); actionRequest.invoke(); assertEquals("-X", actionRequest.data); }
/** * Maps a PUT path. */ public ActionBuilder put(final String path) { return new ActionBuilder().path(path).httpMethod("PUT"); } /**
@Test void testFiltersPassAndInterceptorsStop1() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterPass(1), new FilterPass(2)), arr(new InterceptorPass(1), new InterceptorStop()) ); actionRequest.invoke(); assertEquals("-F1-F2-I1-x-i1-R-f2-f1", actionRequest.data); }
/** * Maps an OPTION path. */ public ActionBuilder options(final String path) { return new ActionBuilder().path(path).httpMethod("OPTIONS"); }
@Test void testFiltersPassAndInterceptorsStop2() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterPass(1), new FilterPass(2)), arr(new InterceptorStop(), new InterceptorPass(2)) ); actionRequest.invoke(); assertEquals("-F1-F2-x-R-f2-f1", actionRequest.data); }
/** * Maps a POST path. */ public ActionBuilder post(final String path) { return new ActionBuilder().path(path).httpMethod("POST"); } /**
@Test void testFiltersPassAndInterceptorsPass() throws Exception { MyActionRequest actionRequest = createMyActionRequest( arr(new FilterPass(1), new FilterPass(2)), arr(new InterceptorPass(1), new InterceptorPass(2)) ); actionRequest.invoke(); assertEquals("-F1-F2-I1-I2-A-i2-i1-R-f2-f1", actionRequest.data); }