Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.TestBean


  }


  @Test
  public void testReplaceArgument() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
    pc.setTarget(tb);
    pc.addAdvisor(new StringSetterNullReplacementAdvice());

    ITestBean t = (ITestBean) pc.getProxy();
View Full Code Here


    assertTrue(t.getName().equals(""));
  }

  @Test
  public void testCanCastProxyToProxyConfig() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(0, di);

    ITestBean t = (ITestBean) createProxy(pc);
View Full Code Here

    assertEquals(2, cba.getCalls());
  }

  @Test
  public void testAdviceImplementsIntroductionInfo() throws Throwable {
    TestBean tb = new TestBean();
    String name = "tony";
    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
View Full Code Here

    assertEquals(ts, intro.getTimeStamp());
  }

  @Test
  public void testCannotAddDynamicIntroductionAdviceExceptInIntroductionAdvice() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    try {
      pc.addAdvice(new DummyIntroductionAdviceImpl());
      fail("Shouldn't be able to add introduction interceptor except via introduction advice");
    }
    catch (AopConfigException ex) {
      assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
    }
    // Check it still works: proxy factory state shouldn't have been corrupted
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

    assertEquals(target.getAge(), proxied.getAge());
  }

  @Test
  public void testRejectsBogusDynamicIntroductionAdviceWithNoAdapter() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    pc.addAdvisor(new DefaultIntroductionAdvisor(new DummyIntroductionAdviceImpl(), Comparable.class));
    try {
      // TODO May fail on either call: may want to tighten up definition
      ITestBean proxied = (ITestBean) createProxy(pc);
View Full Code Here

   * Check that the introduction advice isn't allowed to introduce interfaces
   * that are unsupported by the IntroductionInterceptor.
   */
  @Test
  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);
    }
    // Check it still works: proxy factory state shouldn't have been corrupted
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

   * Note that an introduction can't throw an unexpected checked exception,
   * as it's constained by the interface.
   */
  @Test
  public void testIntroductionThrowsUncheckedException() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);

    @SuppressWarnings("serial")
    class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
      /**
 
View Full Code Here

  /**
   * Should only be able to introduce interfaces, not classes.
   */
  @Test
  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);
    }
    // Check it still works: proxy factory state shouldn't have been corrupted
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

    assertEquals(target.getAge(), proxied.getAge());
  }

  @Test
  public void testCannotAddInterceptorWhenFrozen() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    assertFalse(pc.isFrozen());
    pc.addAdvice(new NopInterceptor());
    ITestBean proxied = (ITestBean) createProxy(pc);
    pc.setFrozen(true);
    try {
      pc.addAdvice(0, new NopInterceptor());
      fail("Shouldn't be able to add interceptor when frozen");
    }
    catch (AopConfigException ex) {
      assertTrue(ex.getMessage().indexOf("frozen") > -1);
    }
    // Check it still works: proxy factory state shouldn't have been corrupted
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, ((Advised) proxied).getAdvisors().length);
  }
View Full Code Here

  /**
   * Check that casting to Advised can't get around advice freeze.
   */
  @Test
  public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    assertFalse(pc.isFrozen());
    pc.addAdvice(new NopInterceptor());
    ITestBean proxied = (ITestBean) createProxy(pc);
    pc.setFrozen(true);
    Advised advised = (Advised) proxied;

    assertTrue(pc.isFrozen());
    try {
      advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
      fail("Shouldn't be able to add Advisor when frozen");
    }
    catch (AopConfigException ex) {
      assertTrue(ex.getMessage().indexOf("frozen") > -1);
    }
    // Check it still works: proxy factory state shouldn't have been corrupted
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, advised.getAdvisors().length);
  }
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.beans.TestBean

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.