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());
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testUserAttributes.
@Test
public void testUserAttributes() throws Throwable {
class MapAwareMethodInterceptor implements MethodInterceptor {
private final Map<String, String> expectedValues;
private final Map<String, String> valuesToAdd;
public MapAwareMethodInterceptor(Map<String, String> expectedValues, Map<String, String> valuesToAdd) {
this.expectedValues = expectedValues;
this.valuesToAdd = valuesToAdd;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
ReflectiveMethodInvocation rmi = (ReflectiveMethodInvocation) invocation;
for (Iterator<String> it = rmi.getUserAttributes().keySet().iterator(); it.hasNext(); ) {
Object key = it.next();
assertEquals(expectedValues.get(key), rmi.getUserAttributes().get(key));
}
rmi.getUserAttributes().putAll(valuesToAdd);
return invocation.proceed();
}
}
;
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
MapAwareMethodInterceptor mami1 = new MapAwareMethodInterceptor(new HashMap<>(), new HashMap<String, String>());
Map<String, String> firstValuesToAdd = new HashMap<>();
firstValuesToAdd.put("test", "");
MapAwareMethodInterceptor mami2 = new MapAwareMethodInterceptor(new HashMap<>(), firstValuesToAdd);
MapAwareMethodInterceptor mami3 = new MapAwareMethodInterceptor(firstValuesToAdd, new HashMap<>());
MapAwareMethodInterceptor mami4 = new MapAwareMethodInterceptor(firstValuesToAdd, new HashMap<>());
Map<String, String> secondValuesToAdd = new HashMap<>();
secondValuesToAdd.put("foo", "bar");
secondValuesToAdd.put("cat", "dog");
MapAwareMethodInterceptor mami5 = new MapAwareMethodInterceptor(firstValuesToAdd, secondValuesToAdd);
Map<String, String> finalExpected = new HashMap<>(firstValuesToAdd);
finalExpected.putAll(secondValuesToAdd);
MapAwareMethodInterceptor mami6 = new MapAwareMethodInterceptor(finalExpected, secondValuesToAdd);
pc.addAdvice(mami1);
pc.addAdvice(mami2);
pc.addAdvice(mami3);
pc.addAdvice(mami4);
pc.addAdvice(mami5);
pc.addAdvice(mami6);
// We don't care about the object
pc.setTarget(new TestBean());
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
String newName = "foo";
tb.setName(newName);
assertEquals(newName, tb.getName());
}
Aggregations