Package org.springframework.tests.sample.beans

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


  @Test
  public void testWithAbstractFactoryBeanAreApplied() {
    ClassPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml");

    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian));
    assertEquals(68, adrian.getAge());
  }
View Full Code Here


    assertEquals(0, counterAspect.count);
  }

  @Test
  public void testProgrammaticProxyCreation() {
    ITestBean testBean = new TestBean();

    AspectJProxyFactory factory = new AspectJProxyFactory();
    factory.setTarget(testBean);

    CounterAspect myCounterAspect = new CounterAspect();
    factory.addAspect(myCounterAspect);

    ITestBean proxyTestBean = factory.getProxy();

    assertTrue("Expected a proxy", proxyTestBean instanceof Advised);
    proxyTestBean.setAge(20);
    assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
  }
View Full Code Here

    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
    pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean tb = (ITestBean) pf1.getProxy();

    assertEquals(age1, tb.getAge());
    tb.setAge(age2);
    assertEquals(age2, tb.getAge());
    assertNull(tb.getName());
    tb.setName(name);
    assertEquals(name, tb.getName());
  }
View Full Code Here

    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvice(new NopInterceptor());
    pf1.addAdvice(new NopInterceptor());
    ITestBean proxies[] = new ITestBean[howMany];
    for (int i = 0; i < howMany; i++) {
      proxies[i] = (ITestBean) createAopProxy(pf1).getProxy();
      assertEquals(age1, proxies[i].getAge());
    }
  }
View Full Code Here

    assertFalse(SerializationTestUtils.isSerializable(tb));

    ProxyFactory pf = new ProxyFactory(tb);

    pf.addAdvice(new NopInterceptor());
    ITestBean proxy = (ITestBean) createAopProxy(pf).getProxy();

    assertFalse(SerializationTestUtils.isSerializable(proxy));
  }
View Full Code Here

    pf1.addAdvice(1, new ProxyMatcherInterceptor());
    pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
    pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
    // Must be first
    pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
    ITestBean advised1 = (ITestBean) pf1.getProxy();
    advised1.setAge(age1); // = 1 invocation

    TestBean target2 = new TestBean();
    ProxyFactory pf2 = new ProxyFactory(target2);
    pf2.setExposeProxy(true);
    NopInterceptor di2 = new NopInterceptor();
    pf2.addAdvice(0, di2);
    pf2.addAdvice(1, new ProxyMatcherInterceptor());
    pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
    pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
    pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
    //System.err.println(pf2.toProxyConfigString());
    ITestBean advised2 = (ITestBean) createProxy(pf2);
    advised2.setAge(age2);
    advised1.setSpouse(advised2); // = 2 invocations

    assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
    assertEquals("Advised two has correct age", age2, advised2.getAge());
    // Means extra call on advised 2
    assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

    assertEquals("one was invoked correct number of times", 4, di1.getCount());
    // Got hit by call to advised1.getSpouse().getAge()
View Full Code Here

    TestBean target1 = new TestBean();
    ProxyFactory pf1 = new ProxyFactory(target1);
    NopInterceptor di1 = new NopInterceptor();
    pf1.addAdvice(0, di1);
    ITestBean advised1 = (ITestBean) createProxy(pf1);
    advised1.setAge(age1); // = 1 invocation
    advised1.setSpouse(advised1); // = 2 invocations

    assertEquals("one was invoked correct number of times", 2, di1.getCount());

    assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
    assertEquals("one was invoked correct number of times", 3, di1.getCount());

    // = 5 invocations, as reentrant call to spouse is advised also
    assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

    assertEquals("one was invoked correct number of times", 5, di1.getCount());
  }
View Full Code Here

    assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#1"));
    assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
  }

  public void testFactoryNesting() {
    ITestBean father = (ITestBean) getBeanFactory().getBean("father");
    assertTrue("Bean from root context", father != null);

    TestBean rod = (TestBean) getBeanFactory().getBean("rod");
    assertTrue("Bean from child context", "Rod".equals(rod.getName()));
    assertTrue("Bean has external reference", rod.getSpouse() == father);
View Full Code Here

      pc.setTarget(new TestBean());
    }
    AopProxy aop = createAopProxy(pc);

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

    ProxyCreatorSupport pc = new ProxyCreatorSupport();
    pc.setInterfaces(new Class<?>[] {ITestBean.class});
    pc.setTarget(raw);

    ITestBean tb = (ITestBean) createProxy(pc);
    assertTrue("this return is wrapped in proxy", tb.getSpouse() == tb);
  }
View Full Code Here

TOP

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

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.