Package org.springframework.tests.sample.beans

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


    assertEquals(1, advised.getAdvisors().length);
  }

  @Test
  public void testCannotRemoveAdvisorWhenFrozen() 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.removeAdvisor(0);
      fail("Shouldn't be able to remove Advisor when frozen");
    }
    catch (AopConfigException ex) {
      assertTrue(ex.getMessage().indexOf("frozen") > -1);
    }
    // Didn't get removed
    assertEquals(1, advised.getAdvisors().length);
    pc.setFrozen(false);
    // Can now remove it
    advised.removeAdvisor(0);
    // Check it still works: proxy factory state shouldn't have been corrupted
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(0, advised.getAdvisors().length);
  }
View Full Code Here


    assertEquals(0, advised.getAdvisors().length);
  }

  @Test
  public void testUseAsHashKey() {
    TestBean target1 = new TestBean();
    ProxyFactory pf1 = new ProxyFactory(target1);
    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>();
View Full Code Here

  /**
   * Check that the string is informative.
   */
  @Test
  public void testProxyConfigString() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    MethodBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
View Full Code Here

    assertTrue(proxyConfigString.indexOf("1 interface") != -1);
  }

  @Test
  public void testCanPreventCastToAdvisedUsingOpaque() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
View Full Code Here

    assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
  }

  @Test
  public void testAdviceSupportListeners() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);

    ProxyFactory pc = new ProxyFactory(target);
    CountingAdvisorListener l = new CountingAdvisorListener(pc);
    pc.addListener(l);
    RefreshCountingAdvisorChainFactory acf = new RefreshCountingAdvisorChainFactory();
    // Should be automatically added as a listener
    pc.addListener(acf);
    assertFalse(pc.isActive());
    assertEquals(0, l.activates);
    assertEquals(0, acf.refreshes);
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertEquals(1, acf.refreshes);
    assertEquals(1, l.activates);
    assertTrue(pc.isActive());
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(0, l.adviceChanges);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(0, di);
    assertEquals(1, l.adviceChanges);
    assertEquals(2, acf.refreshes);
    assertEquals(target.getAge(), proxied.getAge());
    pc.removeAdvice(di);
    assertEquals(2, l.adviceChanges);
    assertEquals(3, acf.refreshes);
    assertEquals(target.getAge(), proxied.getAge());
    pc.getProxy();
    assertEquals(1, l.activates);

    pc.removeListener(l);
    assertEquals(2, l.adviceChanges);
View Full Code Here

@Configuration
public class ConfigForScanning {
  @Bean
  public TestBean testBean() {
    return new TestBean();
  }
View Full Code Here

    assertEquals(2, l.adviceChanges);
  }

  @Test
  public void testExistingProxyChangesTarget() throws Throwable {
    TestBean tb1 = new TestBean();
    tb1.setAge(33);

    TestBean tb2 = new TestBean();
    tb2.setAge(26);
    tb2.setName("Juergen");
    TestBean tb3 = new TestBean();
    tb3.setAge(37);
    ProxyFactory pc = new ProxyFactory(tb1);
    NopInterceptor nop = new NopInterceptor();
    pc.addAdvice(nop);
    ITestBean proxy = (ITestBean) createProxy(pc);
    assertEquals(nop.getCount(), 0);
    assertEquals(tb1.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 1);
    // Change to a new static target
    pc.setTarget(tb2);
    assertEquals(tb2.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 2);

    // Change to a new dynamic target
    HotSwappableTargetSource hts = new HotSwappableTargetSource(tb3);
    pc.setTargetSource(hts);
    assertEquals(tb3.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 3);
    hts.swap(tb1);
    assertEquals(tb1.getAge(), proxy.getAge());
    tb1.setName("Colin");
    assertEquals(tb1.getName(), proxy.getName());
View Full Code Here

  public void testGrandparentNull() {
    assertTrue("grandparent is null", applicationContext.getParent().getParent() == null);
  }

  public void testOverrideWorked() throws Exception {
    TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
    assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
  }
View Full Code Here

    TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
    assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
  }

  public void testGrandparentDefinitionFound() throws Exception {
    TestBean dad = (TestBean) applicationContext.getBean("father");
    assertTrue("Dad has correct name", dad.getName().equals("Albert"));
  }
View Full Code Here

    assertEquals(tb2.getAge(), proxy.getAge());
  }

  @Test
  public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
    TestDynamicPointcutAdvice dp = new TestDynamicPointcutAdvice(new NopInterceptor(), "getAge");
    pc.addAdvisor(dp);
    pc.setTarget(tb);
    ITestBean it = (ITestBean) createProxy(pc);
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.