Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInterceptor


  @Test
  public void testUndeclaredUnheckedException() throws Throwable {
    final RuntimeException unexpectedException = new RuntimeException();
    // Test return value
    MethodInterceptor mi = new MethodInterceptor() {
      @Override
      public Object invoke(MethodInvocation invocation) throws Throwable {
        throw unexpectedException;
      }
    };
View Full Code Here


  public void testCloneInvocationToProceedThreeTimes() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(tb);
    pc.addInterface(ITestBean.class);

    MethodInterceptor twoBirthdayInterceptor = new MethodInterceptor() {
      @Override
      public Object invoke(MethodInvocation mi) throws Throwable {
        // Clone the invocation to proceed three times
        // "The Moor's Last Sigh": this technology can cause premature aging
        MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
View Full Code Here

    pc.addInterface(ITestBean.class);

    /**
     * Changes the name, then changes it back.
     */
    MethodInterceptor nameReverter = new MethodInterceptor() {
      @Override
      public Object invoke(MethodInvocation mi) throws Throwable {
        MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
        String oldName = ((ITestBean) mi.getThis()).getName();
        clone.getArguments()[0] = oldName;
View Full Code Here

    private final AsyncInterface proxy;

    public DynamicAsyncInterfaceBean() {
      ProxyFactory pf = new ProxyFactory(new HashMap<>());
      DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
          if (Future.class.equals(invocation.getMethod().getReturnType())) {
            return new AsyncResult<String>(invocation.getArguments()[0].toString());
View Full Code Here

    private final AsyncMethodsInterface proxy;

    public DynamicAsyncMethodsInterfaceBean() {
      ProxyFactory pf = new ProxyFactory(new HashMap<>());
      DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
          if (Future.class.equals(invocation.getMethod().getReturnType())) {
            return new AsyncResult<String>(invocation.getArguments()[0].toString());
View Full Code Here

  }

  public void testInterceptorIsInvokedWithNoTarget() throws Throwable {
    // Test return value
    int age = 25;
    MethodInterceptor mi = mock(MethodInterceptor.class);

    AdvisedSupport pc = new AdvisedSupport(new Class<?>[] { ITestBean.class });
    pc.addAdvice(mi);
    AopProxy aop = createAopProxy(pc);

    given(mi.invoke(null)).willReturn(age);

    ITestBean tb = (ITestBean) aop.getProxy();
    assertTrue("correct return value", tb.getAge() == age);
  }
View Full Code Here

  private ITestBean getAdvisedProxy(TestBean target) {
    ProxyFactory pf = new ProxyFactory(new Class<?>[]{ITestBean.class});
    pf.setProxyTargetClass(true);

    MethodInterceptor advice = new NopInterceptor();
    Pointcut pointcut = new Pointcut() {
      @Override
      public ClassFilter getClassFilter() {
        return ClassFilter.TRUE;
      }
View Full Code Here

    public static void reset() {
      methodNames.clear();
    }

    public PointcutForVoid() {
      setAdvice(new MethodInterceptor() {
        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
          methodNames.add(invocation.getMethod().getName());
          return invocation.proceed();
        }
View Full Code Here

    // no exception
    tb.hashCode();

    final Exception ex = new UnsupportedOperationException("invoke");
    // Add evil interceptor to head of list
    config.addAdvice(0, new MethodInterceptor() {
      @Override
      public Object invoke(MethodInvocation invocation) throws Throwable {
        throw ex;
      }
    });
View Full Code Here

      }
    }

    SimpleFoo target = new SimpleFoo();
    ProxyFactory factory = new ProxyFactory(target);
    factory.addAdvice(new MethodInterceptor() {
      @Override
      public Object invoke(MethodInvocation invocation) throws Throwable {
        return null;
      }
    });
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInterceptor

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.