use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class IntroductionBenchmarkTests method timeManyInvocations.
@Test
public void timeManyInvocations() {
StopWatch sw = new StopWatch();
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
pf.setProxyTargetClass(false);
pf.addAdvice(new SimpleCounterIntroduction());
ITestBean proxy = (ITestBean) pf.getProxy();
Counter counter = (Counter) proxy;
sw.start(INVOCATIONS + " invocations on proxy, not hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
proxy.getAge();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on proxy, hitting introduction");
for (int i = 0; i < INVOCATIONS; i++) {
counter.getCount();
}
sw.stop();
sw.start(INVOCATIONS + " invocations on target");
for (int i = 0; i < INVOCATIONS; i++) {
target.getAge();
}
sw.stop();
System.out.println(sw.prettyPrint());
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class PerThisAspect method testNamedPointcutFromAspectLibraryWithBinding.
@Test
public void testNamedPointcutFromAspectLibraryWithBinding() {
TestBean target = new TestBean();
ITestBean itb = (ITestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(), "someBean")), ITestBean.class);
itb.setAge(10);
assertEquals("Around advice must apply", 20, itb.getAge());
assertEquals(20, target.getAge());
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class NamedPointcutWithArgs method testBindingInPointcutUsedByAdvice.
@Test(expected = IllegalArgumentException.class)
public void testBindingInPointcutUsedByAdvice() {
TestBean tb = new TestBean();
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
proxyFactory.addAspect(NamedPointcutWithArgs.class);
ITestBean proxiedTestBean = proxyFactory.getProxy();
proxiedTestBean.setName("Supercalifragalisticexpialidocious");
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testSimpleReference.
@Test
public void testSimpleReference() {
String PREFIX = "beans.";
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty(PREFIX + "rod.(class)", TestBean.class.getName());
p.setProperty(PREFIX + "rod.name", "Rod");
p.setProperty(PREFIX + "kerry.(class)", TestBean.class.getName());
p.setProperty(PREFIX + "kerry.name", "Kerry");
p.setProperty(PREFIX + "kerry.age", "35");
p.setProperty(PREFIX + "kerry.spouse(ref)", "rod");
int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, PREFIX);
assertTrue("2 beans registered, not " + count, count == 2);
TestBean kerry = lbf.getBean("kerry", TestBean.class);
assertTrue("Kerry name is Kerry", "Kerry".equals(kerry.getName()));
ITestBean spouse = kerry.getSpouse();
assertTrue("Kerry spouse is non null", spouse != null);
assertTrue("Kerry spouse name is Rod", "Rod".equals(spouse.getName()));
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testTestBeanIntroduction.
private void testTestBeanIntroduction(ProxyFactory pc) {
int newAge = 65;
ITestBean itb = (ITestBean) createProxy(pc);
itb.setAge(newAge);
assertEquals(newAge, itb.getAge());
Lockable lockable = (Lockable) itb;
assertFalse(lockable.locked());
lockable.lock();
assertEquals(newAge, itb.getAge());
try {
itb.setAge(1);
fail("Setters should fail when locked");
} catch (LockedException ex) {
// ok
}
assertEquals(newAge, itb.getAge());
// Unlock
assertTrue(lockable.locked());
lockable.unlock();
itb.setAge(1);
assertEquals(1, itb.getAge());
}
Aggregations