use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AroundAdviceBindingTestAspect method onSetUp.
@BeforeEach
public void onSetUp() throws Exception {
ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
AroundAdviceBindingTestAspect aroundAdviceAspect = ((AroundAdviceBindingTestAspect) ctx.getBean("testAspect"));
ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
assertThat(AopUtils.isAopProxy(injectedTestBean)).isTrue();
this.testBeanProxy = injectedTestBean;
// we need the real target too, not just the proxy...
this.testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();
mockCollaborator = mock(AroundAdviceBindingCollaborator.class);
aroundAdviceAspect.setCollaborator(mockCollaborator);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AfterReturningAdviceBindingTestAspect method testReturningBeanArray.
@Test
public void testReturningBeanArray() {
this.testBeanTarget.setSpouse(new TestBean());
ITestBean[] spouses = this.testBeanTarget.getSpouses();
testBeanProxy.getSpouses();
verify(mockCollaborator).testBeanArrayArg(spouses);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testStaticMethodPointcut.
@Test
public void testStaticMethodPointcut() throws Throwable {
TestBean tb = new TestBean();
ProxyFactory pc = new ProxyFactory();
pc.addInterface(ITestBean.class);
NopInterceptor di = new NopInterceptor();
TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge");
pc.addAdvisor(sp);
pc.setTarget(tb);
ITestBean it = (ITestBean) createProxy(pc);
assertThat(0).isEqualTo(di.getCount());
it.getAge();
assertThat(1).isEqualTo(di.getCount());
it.setAge(11);
assertThat(11).isEqualTo(it.getAge());
assertThat(2).isEqualTo(di.getCount());
}
use of org.springframework.beans.testfixture.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);
assertThat(itb.getAge()).isEqualTo(newAge);
Lockable lockable = (Lockable) itb;
assertThat(lockable.locked()).isFalse();
lockable.lock();
assertThat(itb.getAge()).isEqualTo(newAge);
assertThatExceptionOfType(LockedException.class).isThrownBy(() -> itb.setAge(1));
assertThat(itb.getAge()).isEqualTo(newAge);
// Unlock
assertThat(lockable.locked()).isTrue();
lockable.unlock();
itb.setAge(1);
assertThat(itb.getAge()).isEqualTo(1);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testCannotAddIntroductionAdviceWithUnimplementedInterface.
/**
* 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);
assertThatIllegalArgumentException().isThrownBy(() -> pc.addAdvisor(0, new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor(), ITestBean.class)));
// Check it still works: proxy factory state shouldn't have been corrupted
ITestBean proxied = (ITestBean) createProxy(pc);
assertThat(proxied.getAge()).isEqualTo(target.getAge());
}
Aggregations