@SuppressWarnings({"unchecked"}) @Test public void testExpandStack2() { InjectorsManager injectorsManager = new InjectorsManager(); injectorsManager.scopeDataResolver = new ScopeDataResolver(); injectorsManager.madvocConfig = new MadvocConfig(); injectorsManager.madpc = new PetiteContainer(); injectorsManager.createInjectors(); InterceptorsManager im = new InterceptorsManager(); im.contextInjectorComponent = new ContextInjectorComponent(); im.contextInjectorComponent.injectorsManager = injectorsManager; im.contextInjectorComponent.madvocController = new MadvocController(); im.contextInjectorComponent.scopeDataResolver = injectorsManager.scopeDataResolver; im.contextInjectorComponent.madpc = injectorsManager.madpc; im.madvocConfig = injectorsManager.madvocConfig; im.madvocConfig.defaultInterceptors = new Class[] {EchoInterceptor.class, ServletConfigInterceptor.class, Test2Stack.class}; Class<? extends ActionInterceptor>[] in = new Class[] { DefaultWebAppInterceptors.class, }; Class<? extends ActionInterceptor>[] out = im.replaceSpecialActionWrapper(in); assertEquals(4, out.length); assertEquals(EchoInterceptor.class, out[0]); assertEquals(ServletConfigInterceptor.class, out[1]); assertEquals(AnnotatedPropertyInterceptor.class, out[2]); assertEquals(LogEchoInterceptor.class, out[3]); }
@SuppressWarnings({"unchecked"}) @Test public void testReplace() { InterceptorsManager interceptorsManage = new InterceptorsManager(); interceptorsManage.madvocConfig = new MadvocConfig(); interceptorsManage.madvocConfig.defaultInterceptors = new Class[] {ServletConfigInterceptor.class}; Class<? extends ActionInterceptor>[] in = new Class[] {EchoInterceptor.class, DefaultWebAppInterceptors.class}; Class<? extends ActionInterceptor>[] out = interceptorsManage.replaceSpecialActionWrapper(in); assertEquals(2, out.length); assertEquals(EchoInterceptor.class, out[0]); assertEquals(ServletConfigInterceptor.class, out[1]); }
@SuppressWarnings({"unchecked"}) @Test public void testExpandConfigurableStack() { InjectorsManager injectorsManager = new InjectorsManager(); injectorsManager.scopeDataResolver = new ScopeDataResolver(); injectorsManager.madvocConfig = new MadvocConfig(); injectorsManager.madpc = new PetiteContainer(); InterceptorsManager im = new InterceptorsManager(); im.contextInjectorComponent = new ContextInjectorComponent(); im.contextInjectorComponent.injectorsManager = injectorsManager; im.contextInjectorComponent.madvocController = new MadvocController(); im.contextInjectorComponent.scopeDataResolver = injectorsManager.scopeDataResolver; im.contextInjectorComponent.madpc = injectorsManager.madpc; im.madvocConfig = injectorsManager.madvocConfig; im.madvocConfig.defaultInterceptors = new Class[] {EchoInterceptor.class, ServletConfigInterceptor.class}; injectorsManager.madpc.defineParameter( TestConfigurableStack.class.getName() + ".interceptors", AnnotatedPropertyInterceptor.class.getName() + "," + ServletConfigInterceptor.class.getName() + "," + LogEchoInterceptor.class.getName()); injectorsManager.createInjectors(); Class<? extends ActionInterceptor>[] in = new Class[] { TestConfigurableStack.class, TestConfigurableStack2.class, EchoInterceptor.class }; Class<? extends ActionInterceptor>[] out = im.replaceSpecialActionWrapper(in); assertEquals(6, out.length); // 3 + 2 + 1 // assert: TestConfigurableStack => defined in madpc assertEquals(AnnotatedPropertyInterceptor.class, out[0]); assertEquals(ServletConfigInterceptor.class, out[1]); assertEquals(LogEchoInterceptor.class, out[2]); // assert: TestConfigurableStack2 => madvocConfig.defaultInterceptors assertEquals(EchoInterceptor.class, out[3]); assertEquals(ServletConfigInterceptor.class, out[4]); assertEquals(EchoInterceptor.class, out[5]); }
@SuppressWarnings({"unchecked"}) @Test public void testExpandSelf() { InterceptorsManager im = new InterceptorsManager(); im.madvocConfig = new MadvocConfig(); im.madvocConfig.setDefaultInterceptors( new Class[] { EchoInterceptor.class, DefaultWebAppInterceptors.class // cyclic dependency }); Class<? extends ActionInterceptor>[] in = new Class[] {EchoInterceptor.class, DefaultWebAppInterceptors.class}; try { Class<? extends ActionInterceptor>[] out = im.replaceSpecialActionWrapper(in); fail(); } catch (MadvocException ignore) { } catch (Exception ignored) { fail(); } }
@SuppressWarnings({"unchecked"}) @Test public void testReplace2() { InterceptorsManager im = new InterceptorsManager(); im.madvocConfig = new MadvocConfig(); im.madvocConfig.defaultInterceptors = new Class[] { EchoInterceptor.class, LogEchoInterceptor.class, ServletConfigInterceptor.class }; Class<? extends ActionInterceptor>[] in = new Class[] { AnnotatedPropertyInterceptor.class, DefaultWebAppInterceptors.class, EchoInterceptor.class }; Class<? extends ActionInterceptor>[] out = im.replaceSpecialActionWrapper(in); assertEquals(5, out.length); assertEquals(AnnotatedPropertyInterceptor.class, out[0]); assertEquals(EchoInterceptor.class, out[1]); assertEquals(LogEchoInterceptor.class, out[2]); assertEquals(ServletConfigInterceptor.class, out[3]); assertEquals(EchoInterceptor.class, out[4]); }