Package org.springframework.aop.framework

Examples of org.springframework.aop.framework.ProxyFactory.addAdvisor()


    TimeStamped ts = mock(SubTimeStamped.class);
    long timestamp = 111L;
    given(ts.getTimeStamp()).willReturn(timestamp);

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

    TimeStamped tsp = (TimeStamped) factory.getProxy();
    assertTrue(!(tsp instanceof SubTimeStamped));
    assertTrue(tsp.getTimeStamp() == timestamp);
  }
View Full Code Here


    DelegatingIntroductionInterceptor ii = new DelegatingIntroductionInterceptor(new Tester());

    TestBean target = new TestBean();

    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));

    //assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
    TimeStamped ts = (TimeStamped) pf.getProxy();

    assertTrue(ts.getTimeStamp() == t);
View Full Code Here

    TestBean target = new TestBean();

    ProxyFactory pf = new ProxyFactory(target);
    IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
    assertTrue(ia.isPerInstance());
    pf.addAdvisor(0, ia);

    //assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
    TimeStamped ts = (TimeStamped) pf.getProxy();

    assertThat(ts, instanceOf(TimeStamped.class));
View Full Code Here

    // Test removal
    ii.suppressInterface(TimeStamped.class);
    // Note that we need to construct a new proxy factory,
    // or suppress the interface on the proxy factory
    pf = new ProxyFactory(target);
    pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
    Object o = pf.getProxy();
    assertTrue(!(o instanceof TimeStamped));
  }

  @SuppressWarnings("serial")
View Full Code Here

    assertTrue(! (raw instanceof TimeStamped));
    ProxyFactory factory = new ProxyFactory(raw);

    TimeStamped ts = new SerializableTimeStamped(0);

    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts) {
      @Override
      public String toString() {
        throw new UnsupportedOperationException("Shouldn't be invoked");
      }
    }));
View Full Code Here

    ProxyFactory factory = new ProxyFactory(serializableTarget);
    factory.addInterface(Person.class);
    long time = 1000;
    TimeStamped ts = new SerializableTimeStamped(time);

    factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
    factory.addAdvice(new SerializableNopInterceptor());

    Person p = (Person) factory.getProxy();

    assertEquals(name, p.getName());
View Full Code Here

    // != t
    TestBean target = new TargetClass(t + 1);

    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));

    TimeStamped ts = (TimeStamped) pf.getProxy();
    // From introduction interceptor, not target
    assertTrue(ts.getTimeStamp() == t);
  }
View Full Code Here

    advisor.setAdvice(interceptor);
    advisor.setPointcut(pointcut);

    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);

    return (TestBean) pf.getProxy();
  }

  private void assertMatchesGetAge(MethodMatcher methodMatcher) {
View Full Code Here

  @Test
  public void testNoIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();

    assertFalse("No introduction", proxy instanceof NamedBean);
    // Requires binding
View Full Code Here

  public void testNoIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();

    assertFalse("No introduction", proxy instanceof NamedBean);
    // Requires binding
    proxy.getAge();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.