Package org.strecks.interceptor

Examples of org.strecks.interceptor.AfterInterceptor


    BeforeInterceptor actionBefore2 = createStrictMock(BeforeInterceptor.class);
    List<BeforeInterceptor> actionBefores = new ArrayList<BeforeInterceptor>();
    actionBefores.add(actionBefore1);
    actionBefores.add(actionBefore2);

    AfterInterceptor after1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor after2 = createStrictMock(AfterInterceptor.class);
    Collection<AfterInterceptor> afters = new ArrayList<AfterInterceptor>();
    afters.add(after1);
    afters.add(after2);

    AfterInterceptor actionAfter1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor actionAfter2 = createStrictMock(AfterInterceptor.class);
    List<AfterInterceptor> actionAfters = new ArrayList<AfterInterceptor>();
    actionAfters.add(actionAfter1);
    actionAfters.add(actionAfter2);

    ControllerAction action = createStrictMock(ControllerAction.class);
    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    TestAction actionBean = createStrictMock(TestAction.class);
    ActionBeanSource beanSource = createStrictMock(ActionBeanSource.class);

    ActionContext actionContext = new TestContextImpl(request);

    // check the expected order of method invocation
    expect(action.getBeanSource()).andReturn(beanSource);
    expect(beanSource.createBean(actionContext)).andReturn(actionBean);
    action.preExecute(actionBean, actionContext);

    before1.beforeExecute(actionBean, actionContext);
    before2.beforeExecute(actionBean, actionContext);

    expect(action.getBeforeInterceptors()).andReturn(actionBefores);
    actionBefore1.beforeExecute(actionBean, actionContext);
    actionBefore2.beforeExecute(actionBean, actionContext);

    expect(action.executeController(actionBean, actionContext)).andReturn(
        new ActionForwardViewAdapter(actionForward));

    expect(action.getAfterInterceptors()).andReturn(actionAfters);
    actionAfter1.afterExecute(actionBean, actionContext, null);
    actionAfter2.afterExecute(actionBean, actionContext, null);

    after1.afterExecute(actionBean, actionContext, null);
    after2.afterExecute(actionBean, actionContext, null);
    action.postExecute(actionBean, actionContext, null);
View Full Code Here


    BeforeInterceptor before2 = createStrictMock(BeforeInterceptor.class);
    Collection<BeforeInterceptor> befores = new ArrayList<BeforeInterceptor>();
    befores.add(before1);
    befores.add(before2);

    AfterInterceptor after1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor after2 = createStrictMock(AfterInterceptor.class);
    Collection<AfterInterceptor> afters = new ArrayList<AfterInterceptor>();
    afters.add(after1);
    afters.add(after2);

    AfterInterceptor actionAfter1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor actionAfter2 = createStrictMock(AfterInterceptor.class);
    List<AfterInterceptor> actionAfters = new ArrayList<AfterInterceptor>();
    actionAfters.add(actionAfter1);
    actionAfters.add(actionAfter2);

    ControllerAction action = createStrictMock(ControllerAction.class);
    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    TestAction actionBean = createStrictMock(TestAction.class);
    ActionBeanSource beanSource = createStrictMock(ActionBeanSource.class);

    ActionContext actionContext = new TestContextImpl(request);

    // check the expected order of method invocation
    expect(action.getBeanSource()).andReturn(beanSource);
    expect(beanSource.createBean(actionContext)).andReturn(actionBean);
    action.preExecute(actionBean, actionContext);

    IllegalStateException exception = new IllegalStateException();

    // now expected mock calls
    before1.beforeExecute(actionBean, actionContext);
    expectLastCall().andThrow(exception);

    expect(action.getAfterInterceptors()).andReturn(actionAfters);
    actionAfter1.afterExecute(actionBean, actionContext, exception);
    actionAfter2.afterExecute(actionBean, actionContext, exception);

    after1.afterExecute(actionBean, actionContext, exception);
    after2.afterExecute(actionBean, actionContext, exception);
    action.postExecute(actionBean, actionContext, exception);
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testThrowOnAfter() throws Exception
  {

    AfterInterceptor after1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor after2 = createStrictMock(AfterInterceptor.class);
    Collection<AfterInterceptor> afters = new ArrayList<AfterInterceptor>();
    afters.add(after1);
    afters.add(after2);

    ControllerAction action = createStrictMock(ControllerAction.class);
    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    TestAction actionBean = createStrictMock(TestAction.class);
    ActionBeanSource beanSource = createStrictMock(ActionBeanSource.class);

    ActionContext actionContext = new TestContextImpl(request);

    // check the expected order of method invocation
    expect(action.getBeanSource()).andReturn(beanSource);
    expect(beanSource.createBean(actionContext)).andReturn(actionBean);
    action.preExecute(actionBean, actionContext);

    expect(action.getBeforeInterceptors()).andReturn(null);
    expect(action.executeController(actionBean, actionContext)).andReturn(null);
    expect(action.getAfterInterceptors()).andReturn(null);

    IllegalStateException exception = new IllegalStateException();
    after1.afterExecute(actionBean, actionContext, null);
    expectLastCall().andThrow(exception);

    // check that we continue - i.e we don't fall over in a heap because the after interceptor
    // failed
    after2.afterExecute(actionBean, actionContext, null);
    request.setAttribute(InfrastructureKeys.ACTION_BEAN, actionBean);
    action.postExecute(actionBean, actionContext, null);

    replay(action);
    replay(request);
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testThrowClassCastOnAfter() throws Exception
  {

    AfterInterceptor after1 = createStrictMock(AfterInterceptor.class);
    AfterInterceptor after2 = createStrictMock(AfterInterceptor.class);
    Collection<AfterInterceptor> afters = new ArrayList<AfterInterceptor>();
    afters.add(after1);
    afters.add(after2);

    ControllerAction action = createStrictMock(ControllerAction.class);
View Full Code Here

    }

    Set<String> afterNames = config.getAfterInterceptors();
    for (String className : afterNames)
    {
      AfterInterceptor interceptor = ReflectHelper.createInstance(className, AfterInterceptor.class);
      afterInterceptors.add(interceptor);
    }
  }
View Full Code Here

  void readAfterInterceptors(AfterInterceptors interceptors, Class actionBeanClass)
  {
    Class[] classes = interceptors.classes();
    for (Class clazz : classes)
    {
      AfterInterceptor instance = ReflectHelper.createInstance(clazz, AfterInterceptor.class);
      addAfterInterceptor(instance);
    }
  }
View Full Code Here

TOP

Related Classes of org.strecks.interceptor.AfterInterceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.