Package org.springframework.aop.support

Examples of org.springframework.aop.support.DefaultIntroductionAdvisor


  public void testCannotAddIntroductionAdviceWithUnimplementedInterface() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    try {
      pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class));
      fail("Shouldn't be able to add introduction advice introducing an unimplemented interface");
    }
    catch (IllegalArgumentException ex) {
      //assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
    }
View Full Code Here


      @Override
      public long getTimeStamp() {
        throw new UnsupportedOperationException();
      }
    }
    pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));

    TimeStamped ts = (TimeStamped) createProxy(pc);
    try {
      ts.getTimeStamp();
      fail("Should throw UnsupportedOperationException");
View Full Code Here

  public void testCannotAddIntroductionAdviceToIntroduceClass() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    try {
      pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), TestBean.class));
      fail("Shouldn't be able to add introduction advice that introduces a class, rather than an interface");
    }
    catch (IllegalArgumentException ex) {
      assertTrue(ex.getMessage().indexOf("interface") > -1);
    }
View Full Code Here

    pf1.addAdvice(new NopInterceptor());
    ITestBean proxy1 = (ITestBean) createProxy(pf1);

    TestBean target2 = new TestBean();
    ProxyFactory pf2 = new ProxyFactory(target2);
    pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean proxy2 = (ITestBean) createProxy(pf2);

    HashMap<ITestBean, Object> h = new HashMap<ITestBean, Object>();
    Object value1 = "foo";
    Object value2 = "bar";
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());
          }
          return null;
        }
      });
      advisor.addInterface(AsyncInterface.class);
      pf.addAdvisor(advisor);
      this.proxy = (AsyncInterface) pf.getProxy();
    }
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());
          }
          return null;
        }
      });
      advisor.addInterface(AsyncMethodsInterface.class);
      pf.addAdvisor(advisor);
      this.proxy = (AsyncMethodsInterface) pf.getProxy();
    }
View Full Code Here

    long time = 666L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
    ti.setTime(time);
    // Add to head of interceptor chain
    int oldCount = config.getAdvisors().length;
    config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    assertTrue(config.getAdvisors().length == oldCount + 1);

    TimeStamped ts = (TimeStamped) factory.getBean("test2");
    assertEquals(time, ts.getTimeStamp());
View Full Code Here

  public void addAdvice(int pos, Advice advice) throws AopConfigException {
    Assert.notNull(advice, "Advice must not be null");
    if (advice instanceof IntroductionInfo) {
      // We don't need an IntroductionAdvisor for this kind of introduction:
      // It's fully self-describing.
      addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
    }
    else if (advice instanceof DynamicIntroductionAdvice) {
      // We need an IntroductionAdvisor for this kind of introduction.
      throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
    }
View Full Code Here

    long t = 555555L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);

    Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

    Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
    assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);

    TimeStamped ts = (TimeStamped) factory.getProxy();
View Full Code Here

    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
    ti.setTime(time);

    // Add to front of interceptor chain
    int oldCount = config.getAdvisors().length;
    config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

    assertTrue(config.getAdvisors().length == oldCount + 1);

    TimeStamped ts = (TimeStamped) config.getProxy();
    assertTrue(ts.getTimeStamp() == time);
View Full Code Here

TOP

Related Classes of org.springframework.aop.support.DefaultIntroductionAdvisor

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.