Here are the examples of the java api org.springframework.tests.sample.beans.ITestBean taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
263 Examples
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy() {
this.factory.preInstantiateSingletons();
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2DynamicProxy");
replacedertTrue("testBean is a dynamic proxy", Proxy.isProxyClreplaced(testBean.getClreplaced()));
replacedertTrue(testBean instanceof TransactionalProxy);
doTestGetsAreNotTransactional(testBean);
}
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private void doTestGetsAreNotTransactional(final ITestBean testBean) {
// Install facade
PlatformTransactionManager ptm = mock(PlatformTransactionManager.clreplaced);
PlatformTransactionManagerFacade.delegate = ptm;
replacedertTrue("Age should not be " + testBean.getAge(), testBean.getAge() == 666);
// Expect no methods
verifyZeroInteractions(ptm);
// Install facade expecting a call
final TransactionStatus ts = mock(TransactionStatus.clreplaced);
ptm = new PlatformTransactionManager() {
private boolean invoked;
@Override
public TransactionStatus getTransaction(@Nullable TransactionDefinition def) throws TransactionException {
if (invoked) {
throw new IllegalStateException("getTransaction should not get invoked more than once");
}
invoked = true;
if (!(def.getName().contains(DerivedTestBean.clreplaced.getName()) && def.getName().contains("setAge"))) {
throw new IllegalStateException("transaction name should contain clreplaced and method name: " + def.getName());
}
return ts;
}
@Override
public void commit(TransactionStatus status) throws TransactionException {
replacedertTrue(status == ts);
}
@Override
public void rollback(TransactionStatus status) throws TransactionException {
throw new IllegalStateException("rollback should not get invoked");
}
};
PlatformTransactionManagerFacade.delegate = ptm;
// TODO same as old age to avoid ordering effect for now
int age = 666;
testBean.setAge(age);
replacedertTrue(testBean.getAge() == age);
}
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Cglib");
replacedertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(testBean));
replacedertTrue(testBean instanceof TransactionalProxy);
doTestGetsAreNotTransactional(testBean);
}
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetsAreNotTransactionalWithProxyFactory1() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory1");
replacedertTrue("testBean is a dynamic proxy", Proxy.isProxyClreplaced(testBean.getClreplaced()));
replacedertFalse(testBean instanceof TransactionalProxy);
doTestGetsAreNotTransactional(testBean);
}
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetsAreNotTransactionalWithProxyFactory3() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory3");
replacedertTrue("testBean is a full proxy", testBean instanceof DerivedTestBean);
replacedertTrue(testBean instanceof TransactionalProxy);
InvocationCounterPointcut txnCounter = (InvocationCounterPointcut) factory.getBean("txnInvocationCounterPointcut");
InvocationCounterInterceptor preCounter = (InvocationCounterInterceptor) factory.getBean("preInvocationCounterInterceptor");
InvocationCounterInterceptor postCounter = (InvocationCounterInterceptor) factory.getBean("postInvocationCounterInterceptor");
txnCounter.counter = 0;
preCounter.counter = 0;
postCounter.counter = 0;
doTestGetsAreNotTransactional(testBean);
// Can't replacedert it's equal to 4 as the pointcut may be optimized and only invoked once
replacedertTrue(0 < txnCounter.counter && txnCounter.counter <= 4);
replacedertEquals(4, preCounter.counter);
replacedertEquals(4, postCounter.counter);
}
19
Source : BeanFactoryTransactionTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testProxyFactory2Lazy() {
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Lazy");
replacedertFalse(factory.containsSingleton("target"));
replacedertEquals(666, testBean.getAge());
replacedertTrue(factory.containsSingleton("target"));
}
19
Source : XmlBeanFactoryTestTypes.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Bean testing the ability to use both lookup method overrides
* and constructor injection.
* There is also a property ("setterString") to be set via
* Setter Injection.
*
* @author Rod Johnson
*/
abstract clreplaced ConstructorInjectedOverrides {
private ITestBean tb;
private String setterString;
public ConstructorInjectedOverrides(ITestBean tb) {
this.tb = tb;
}
public ITestBean getTestBean() {
return this.tb;
}
protected abstract FactoryMethods createFactoryMethods();
public String getSetterString() {
return setterString;
}
public void setSetterString(String setterString) {
this.setterString = setterString;
}
}
19
Source : CustomNamespaceHandlerTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testProxyingDecorator() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
replacedertTestBean(bean);
replacedertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
replacedertEquals("Incorrect number of advisors", 1, advisors.length);
replacedertEquals("Incorrect advice clreplaced", DebugInterceptor.clreplaced, advisors[0].getAdvice().getClreplaced());
}
19
Source : CustomNamespaceHandlerTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private void replacedertTestBean(ITestBean bean) {
replacedertEquals("Invalid name", "Rob Harrop", bean.getName());
replacedertEquals("Invalid age", 23, bean.getAge());
}
19
Source : CustomNamespaceHandlerTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testChainedDecorators() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
replacedertTestBean(bean);
replacedertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
replacedertEquals("Incorrect number of advisors", 2, advisors.length);
replacedertEquals("Incorrect advice clreplaced", DebugInterceptor.clreplaced, advisors[0].getAdvice().getClreplaced());
replacedertEquals("Incorrect advice clreplaced", NopInterceptor.clreplaced, advisors[1].getAdvice().getClreplaced());
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testCanGetFactoryReferenceAndManipulate() {
ProxyFactoryBean config = (ProxyFactoryBean) factory.getBean("&test1");
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(config.getObjectType()));
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(factory.getType("test1")));
// Trigger lazy initialization.
config.getObject();
replacedertEquals("Have one advisors", 1, config.getAdvisors().length);
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(config.getObjectType()));
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(factory.getType("test1")));
ITestBean tb = (ITestBean) factory.getBean("test1");
// no exception
tb.hashCode();
final Exception ex = new UnsupportedOperationException("invoke");
// Add evil interceptor to head of list
config.addAdvice(0, new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
throw ex;
}
});
replacedertEquals("Have correct advisor count", 2, config.getAdvisors().length);
tb = (ITestBean) factory.getBean("test1");
try {
// Will fail now
tb.toString();
fail("Evil interceptor added programmatically should fail all method calls");
} catch (Exception thrown) {
replacedertTrue(thrown == ex);
}
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testIsDynamicProxyWhenAutodetectingInterfacesForPrototype() {
ITestBean test1 = (ITestBean) factory.getBean("test4");
replacedertTrue("test4 is a dynamic proxy", Proxy.isProxyClreplaced(test1.getClreplaced()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetObjectTypeWithTargetViaTargetSource() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClreplacedPathResource(TARGETSOURCE_CONTEXT, CLreplaced));
ITestBean tb = (ITestBean) bf.getBean("viaTargetSource");
replacedertTrue(tb.getName().equals("Adam"));
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource");
replacedertTrue("Has correct object type", TestBean.clreplaced.isreplacedignableFrom(pfb.getObjectType()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testMethodPointcuts() {
ITestBean tb = (ITestBean) factory.getBean("pointcuts");
PointcutForVoid.reset();
replacedertTrue("No methods intercepted", PointcutForVoid.methodNames.isEmpty());
tb.getAge();
replacedertTrue("Not void: shouldn't have intercepted", PointcutForVoid.methodNames.isEmpty());
tb.setAge(1);
tb.getAge();
tb.setName("Tristan");
tb.toString();
replacedertEquals("Recorded wrong number of invocations", 2, PointcutForVoid.methodNames.size());
replacedertTrue(PointcutForVoid.methodNames.get(0).equals("setAge"));
replacedertTrue(PointcutForVoid.methodNames.get(1).equals("setName"));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Test invoker is automatically added to manipulate target.
*/
@Test
public void testAutoInvoker() {
String name = "Hieronymous";
TestBean target = (TestBean) factory.getBean("test");
target.setName(name);
ITestBean autoInvoker = (ITestBean) factory.getBean("autoInvoker");
replacedertTrue(autoInvoker.getName().equals(name));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Note that we can't add or remove interfaces without reconfiguring the
* singleton.
*/
@Test
public void testCanAddAndRemoveAdvicesOnSingleton() {
ITestBean it = (ITestBean) factory.getBean("test1");
Advised pc = (Advised) it;
it.getAge();
NopInterceptor di = new NopInterceptor();
pc.addAdvice(0, di);
replacedertEquals(0, di.getCount());
it.setAge(25);
replacedertEquals(25, it.getAge());
replacedertEquals(2, di.getCount());
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testIsDynamicProxyWhenInterfaceSpecifiedForPrototype() {
ITestBean test1 = (ITestBean) factory.getBean("test2");
replacedertTrue("test2 is a dynamic proxy", Proxy.isProxyClreplaced(test1.getClreplaced()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testPrototypeInterceptorSingletonTarget() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClreplacedPathResource(CONTEXT, CLreplaced));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
bean1.setAge(1);
bean2.setAge(2);
replacedertEquals(2, bean1.getAge());
((Lockable) bean1).lock();
try {
bean1.setAge(5);
fail("expected LockedException");
} catch (LockedException ex) {
// expected
}
try {
bean2.setAge(6);
} catch (LockedException ex) {
fail("did not expect LockedException");
}
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetObjectTypeWithNoTargetOrTargetSource() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClreplacedPathResource(TARGETSOURCE_CONTEXT, CLreplaced));
ITestBean tb = (ITestBean) bf.getBean("noTarget");
try {
tb.getName();
fail();
} catch (UnsupportedOperationException ex) {
replacedertEquals("getName", ex.getMessage());
}
FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget");
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(pfb.getObjectType()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testIsDynamicProxyWhenAutodetectingInterfaces() {
ITestBean test1 = (ITestBean) factory.getBean("test3");
replacedertTrue("test3 is a dynamic proxy", Proxy.isProxyClreplaced(test1.getClreplaced()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testPrototypeInstancesAreNotEqual() {
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(factory.getType("prototype")));
ITestBean test2 = (ITestBean) factory.getBean("prototype");
ITestBean test2_1 = (ITestBean) factory.getBean("prototype");
replacedertTrue("Prototype instances !=", test2 != test2_1);
replacedertTrue("Prototype instances equal", test2.equals(test2_1));
replacedertTrue("Has correct object type", ITestBean.clreplaced.isreplacedignableFrom(factory.getType("prototype")));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testPrototypeAdvisor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClreplacedPathResource(CONTEXT, CLreplaced));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
bean1.setAge(3);
bean2.setAge(4);
replacedertEquals(3, bean1.getAge());
replacedertEquals(4, bean2.getAge());
((Lockable) bean1).lock();
try {
bean1.setAge(5);
fail("expected LockedException");
} catch (LockedException ex) {
// expected
}
try {
bean2.setAge(6);
} catch (LockedException ex) {
fail("did not expect LockedException");
}
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testIsDynamicProxyWhenInterfaceSpecified() {
ITestBean test1 = (ITestBean) factory.getBean("test1");
replacedertTrue("test1 is a dynamic proxy", Proxy.isProxyClreplaced(test1.getClreplaced()));
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Test that inner bean for target means that we can use
* autowire without ambiguity from target and proxy
*/
@Test
public void testTargetAsInnerBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClreplacedPathResource(INNER_BEAN_TARGET_CONTEXT, CLreplaced));
ITestBean itb = (ITestBean) bf.getBean("testBean");
replacedertEquals("innerBeanTarget", itb.getName());
replacedertEquals("Only have proxy and interceptor: no target", 3, bf.getBeanDefinitionCount());
DependsOnITestBean doit = (DependsOnITestBean) bf.getBean("autowireCheck");
replacedertSame(itb, doit.tb);
}
19
Source : ProxyFactoryBeanTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* The instances are equal, but do not have object idenreplacedy.
* Interceptors and interfaces and the target are the same.
*/
@Test
public void testSingletonInstancesAreEqual() {
ITestBean test1 = (ITestBean) factory.getBean("test1");
ITestBean test1_1 = (ITestBean) factory.getBean("test1");
// replacedertTrue("Singleton instances ==", test1 == test1_1);
replacedertEquals("Singleton instances ==", test1, test1_1);
test1.setAge(25);
replacedertEquals(test1.getAge(), test1_1.getAge());
test1.setAge(250);
replacedertEquals(test1.getAge(), test1_1.getAge());
Advised pc1 = (Advised) test1;
Advised pc2 = (Advised) test1_1;
replacedertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
int oldLength = pc1.getAdvisors().length;
NopInterceptor di = new NopInterceptor();
pc1.addAdvice(1, di);
replacedertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
replacedertEquals("Now have one more advisor", oldLength + 1, pc2.getAdvisors().length);
replacedertEquals(di.getCount(), 0);
test1.setAge(5);
replacedertEquals(test1_1.getAge(), test1.getAge());
replacedertEquals(di.getCount(), 3);
}
19
Source : AutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAutoProxyCreatorWithFallbackToDynamicProxy() {
StaticApplicationContext sac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("proxyFactoryBean", "false");
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.clreplaced, pvs);
sac.registerSingleton("noInterfaces", NoInterfaces.clreplaced);
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.clreplaced);
sac.registerSingleton("singletonNoInterceptor", CustomProxyFactoryBean.clreplaced);
sac.registerSingleton("singletonToBeProxied", CustomProxyFactoryBean.clreplaced);
sac.registerPrototype("prototypeToBeProxied", SpringProxyFactoryBean.clreplaced);
sac.refresh();
MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
replacedertFalse(AopUtils.isCglibProxy(messageSource));
replacedertTrue(AopUtils.isCglibProxy(noInterfaces));
replacedertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
replacedertFalse(AopUtils.isCglibProxy(singletonNoInterceptor));
replacedertFalse(AopUtils.isCglibProxy(singletonToBeProxied));
replacedertFalse(AopUtils.isCglibProxy(prototypeToBeProxied));
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonNoInterceptor.getName();
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonToBeProxied.getAge();
replacedertEquals(1, tapc.testInterceptor.nrOfInvocations);
prototypeToBeProxied.getSpouse();
replacedertEquals(2, tapc.testInterceptor.nrOfInvocations);
}
19
Source : AutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAutoProxyCreatorWithFallbackToTargetClreplaced() {
StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", FallbackTestAutoProxyCreator.clreplaced);
sac.registerSingleton("noInterfaces", NoInterfaces.clreplaced);
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.clreplaced);
sac.registerSingleton("singletonNoInterceptor", TestBean.clreplaced);
sac.registerSingleton("singletonToBeProxied", TestBean.clreplaced);
sac.registerPrototype("prototypeToBeProxied", TestBean.clreplaced);
sac.refresh();
MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
replacedertFalse(AopUtils.isCglibProxy(messageSource));
replacedertTrue(AopUtils.isCglibProxy(noInterfaces));
replacedertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
replacedertFalse(AopUtils.isCglibProxy(singletonNoInterceptor));
replacedertFalse(AopUtils.isCglibProxy(singletonToBeProxied));
replacedertFalse(AopUtils.isCglibProxy(prototypeToBeProxied));
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonNoInterceptor.getName();
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonToBeProxied.getAge();
replacedertEquals(1, tapc.testInterceptor.nrOfInvocations);
prototypeToBeProxied.getSpouse();
replacedertEquals(2, tapc.testInterceptor.nrOfInvocations);
}
19
Source : AutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testCustomAutoProxyCreator() {
StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.clreplaced);
sac.registerSingleton("noInterfaces", NoInterfaces.clreplaced);
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.clreplaced);
sac.registerSingleton("singletonNoInterceptor", TestBean.clreplaced);
sac.registerSingleton("singletonToBeProxied", TestBean.clreplaced);
sac.registerPrototype("prototypeToBeProxied", TestBean.clreplaced);
sac.refresh();
MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
replacedertFalse(AopUtils.isCglibProxy(messageSource));
replacedertTrue(AopUtils.isCglibProxy(noInterfaces));
replacedertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
replacedertTrue(AopUtils.isCglibProxy(singletonNoInterceptor));
replacedertTrue(AopUtils.isCglibProxy(singletonToBeProxied));
replacedertTrue(AopUtils.isCglibProxy(prototypeToBeProxied));
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonNoInterceptor.getName();
replacedertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonToBeProxied.getAge();
replacedertEquals(1, tapc.testInterceptor.nrOfInvocations);
prototypeToBeProxied.getSpouse();
replacedertEquals(2, tapc.testInterceptor.nrOfInvocations);
}
19
Source : AopNamespaceHandlerTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
public void mySetAgeAdvice(int newAge, ITestBean bean) {
// no-op
}
19
Source : DeclareParentsTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Rod Johnson
* @author Chris Beams
*/
public clreplaced DeclareParentsTests {
private ITestBean testBeanProxy;
private Object introductionObject;
@Before
public void setup() {
ClreplacedPathXmlApplicationContext ctx = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + ".xml", getClreplaced());
testBeanProxy = (ITestBean) ctx.getBean("testBean");
introductionObject = ctx.getBean("introduction");
}
@Test
public void testIntroductionWasMade() {
replacedertTrue(AopUtils.isAopProxy(testBeanProxy));
replacedertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject));
replacedertTrue("Introduction must have been made", testBeanProxy instanceof Lockable);
}
// TODO if you change type pattern from org.springframework.beans..*
// to org.springframework..* it also matches introduction.
// Perhaps generated advisor bean definition could be made to depend
// on the introduction, in which case this would not be a problem.
@Test
public void testLockingWorks() {
Lockable lockable = (Lockable) testBeanProxy;
replacedertFalse(lockable.locked());
// Invoke a non-advised method
testBeanProxy.getAge();
testBeanProxy.setName("");
lockable.lock();
try {
testBeanProxy.setName(" ");
fail("Should be locked");
} catch (IllegalStateException ex) {
// expected
}
}
}
19
Source : BeanNamePointcutAtAspectTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Test for correct application of the bean() PCD for @AspectJ-based aspects.
*
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Chris Beams
*/
public clreplaced BeanNamePointcutAtAspectTests {
private ITestBean testBean1;
private ITestBean testBean3;
private CounterAspect counterAspect;
@org.junit.Before
public void setup() {
ClreplacedPathXmlApplicationContext ctx = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + ".xml", getClreplaced());
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
testBean1 = (ITestBean) ctx.getBean("testBean1");
testBean3 = (ITestBean) ctx.getBean("testBean3");
}
@Test
public void testMatchingBeanName() {
replacedertTrue("Expected a proxy", testBean1 instanceof Advised);
// Call two methods to test for SPR-3953-like condition
testBean1.setAge(20);
testBean1.setName("");
replacedertEquals(2, counterAspect.count);
}
@Test
public void testNonMatchingBeanName() {
replacedertFalse("Didn't expect a proxy", testBean3 instanceof Advised);
testBean3.setAge(20);
replacedertEquals(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();
replacedertTrue("Expected a proxy", proxyTestBean instanceof Advised);
proxyTestBean.setAge(20);
replacedertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
}
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testIncludeMechanism() {
ClreplacedPathXmlApplicationContext bf = newContext("usesInclude.xml");
ITestBean adrian = (ITestBean) bf.getBean("adrian");
replacedertTrue(AopUtils.isAopProxy(adrian));
replacedertEquals(68, adrian.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testTwoAdviceAspect() {
ClreplacedPathXmlApplicationContext bf = newContext("twoAdviceAspect.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
testAgeAspect(adrian1, 0, 2);
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testWithBeanNameAutoProxyCreator() {
ClreplacedPathXmlApplicationContext bf = newContext("withBeanNameAutoProxyCreator.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
replacedertEquals(68, tb.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testMultipleAspectsWithParameterApplied() {
ClreplacedPathXmlApplicationContext bf = newContext("aspects.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
tb.setAge(10);
replacedertEquals(20, tb.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testWithAbstractFactoryBeanAreApplied() {
ClreplacedPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml");
ITestBean adrian = (ITestBean) bf.getBean("adrian");
replacedertTrue(AopUtils.isAopProxy(adrian));
replacedertEquals(68, adrian.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testTwoAdviceAspectSingleton() {
ClreplacedPathXmlApplicationContext bf = newContext("twoAdviceAspectSingleton.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
testAgeAspect(adrian1, 0, 1);
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
replacedertNotSame(adrian1, adrian2);
testAgeAspect(adrian2, 2, 1);
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAspectsAndAdvisorAreApplied() {
ClreplacedPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian");
doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
protected void doTestAspectsAndAdvisorAreApplied(ApplicationContext ac, ITestBean shouldBeWeaved) {
TestBeanAdvisor tba = (TestBeanAdvisor) ac.getBean("advisor");
MultiplyReturnValue mrv = (MultiplyReturnValue) ac.getBean("aspect");
replacedertEquals(3, mrv.getMultiple());
tba.count = 0;
mrv.invocations = 0;
replacedertTrue("Autoproxying must apply from @AspectJ aspect", AopUtils.isAopProxy(shouldBeWeaved));
replacedertEquals("Adrian", shouldBeWeaved.getName());
replacedertEquals(0, mrv.invocations);
replacedertEquals(34 * mrv.getMultiple(), shouldBeWeaved.getAge());
replacedertEquals("Spring advisor must be invoked", 2, tba.count);
replacedertEquals("Must be able to hold state in aspect", 1, mrv.invocations);
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private void testAgeAspect(ITestBean adrian, int start, int increment) {
replacedertTrue(AopUtils.isAopProxy(adrian));
adrian.setName("");
replacedertEquals(start, adrian.age());
int newAge = 32;
adrian.setAge(newAge);
replacedertEquals(start + increment, adrian.age());
adrian.setAge(0);
replacedertEquals(start + increment * 2, adrian.age());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testTwoAdviceAspectPrototype() {
ClreplacedPathXmlApplicationContext bf = newContext("twoAdviceAspectPrototype.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
testAgeAspect(adrian1, 0, 1);
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
replacedertNotSame(adrian1, adrian2);
testAgeAspect(adrian2, 0, 1);
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAspectsAreAppliedInDefinedOrder() {
ClreplacedPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
replacedertEquals(71, tb.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testPerThisAspect() {
ClreplacedPathXmlApplicationContext bf = newContext("perthis.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
replacedertTrue(AopUtils.isAopProxy(adrian1));
replacedertEquals(0, adrian1.getAge());
replacedertEquals(1, adrian1.getAge());
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
replacedertNotSame(adrian1, adrian2);
replacedertTrue(AopUtils.isAopProxy(adrian1));
replacedertEquals(0, adrian2.getAge());
replacedertEquals(1, adrian2.getAge());
replacedertEquals(2, adrian2.getAge());
replacedertEquals(3, adrian2.getAge());
replacedertEquals(2, adrian1.getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAspectsAreApplied() {
ClreplacedPathXmlApplicationContext bf = newContext("aspects.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
replacedertEquals(68, tb.getAge());
MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean");
replacedertTrue(AopUtils.isAopProxy(factoryBean.getTargetObject()));
replacedertEquals(68, ((ITestBean) factoryBean.getTargetObject()).getAge());
}
19
Source : AspectJAutoProxyCreatorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testAdviceUsingJoinPoint() {
ClreplacedPathXmlApplicationContext bf = newContext("usesJoinPointAspect.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
adrian1.getAge();
AdviceUsingThisJoinPoint aspectInstance = (AdviceUsingThisJoinPoint) bf.getBean("aspect");
// (AdviceUsingThisJoinPoint) Aspects.aspectOf(AdviceUsingThisJoinPoint.clreplaced);
// replacedertEquals("method-execution(int TestBean.getAge())",aspectInstance.getLastMethodEntered());
replacedertTrue(aspectInstance.getLastMethodEntered().indexOf("TestBean.getAge())") != 0);
}
19
Source : AspectJExpressionPointcutAdvisorTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Chris Beams
*/
public clreplaced AspectJExpressionPointcutAdvisorTests {
private ITestBean testBean;
private CallCountingInterceptor interceptor;
@Before
public void setup() {
ClreplacedPathXmlApplicationContext ctx = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + ".xml", getClreplaced());
testBean = (ITestBean) ctx.getBean("testBean");
interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
}
@Test
public void testPointcutting() {
replacedertEquals("Count should be 0", 0, interceptor.getCount());
testBean.getSpouses();
replacedertEquals("Count should be 1", 1, interceptor.getCount());
testBean.getSpouse();
replacedertEquals("Count should be 1", 1, interceptor.getCount());
}
}
19
Source : AspectAndAdvicePrecedenceTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* @author Adrian Colyer
* @author Chris Beams
*/
public clreplaced AspectAndAdvicePrecedenceTests {
private PrecedenceTestAspect highPrecedenceAspect;
private PrecedenceTestAspect lowPrecedenceAspect;
private SimpleSpringBeforeAdvice highPrecedenceSpringAdvice;
private SimpleSpringBeforeAdvice lowPrecedenceSpringAdvice;
private ITestBean testBean;
@Before
public void setup() {
ClreplacedPathXmlApplicationContext ctx = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + ".xml", getClreplaced());
highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
lowPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("lowPrecedenceSpringAdvice");
testBean = (ITestBean) ctx.getBean("testBean");
}
@Test
public void testAdviceOrder() {
PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
this.highPrecedenceAspect.setCollaborator(collaborator);
this.lowPrecedenceAspect.setCollaborator(collaborator);
this.highPrecedenceSpringAdvice.setCollaborator(collaborator);
this.lowPrecedenceSpringAdvice.setCollaborator(collaborator);
this.testBean.getAge();
}
private static clreplaced PrecedenceVerifyingCollaborator implements PrecedenceTestAspect.Collaborator {
private static final String[] EXPECTED = { // this order confirmed by running the same aspects (minus the Spring AOP advisors)
// through AspectJ...
// 1
"beforeAdviceOne(highPrecedenceAspect)", // 2
"beforeAdviceTwo(highPrecedenceAspect)", // 3, before proceed
"aroundAdviceOne(highPrecedenceAspect)", // 4, before proceed
"aroundAdviceTwo(highPrecedenceAspect)", // 5
"beforeAdviceOne(highPrecedenceSpringAdvice)", // 6
"beforeAdviceOne(lowPrecedenceSpringAdvice)", // 7
"beforeAdviceOne(lowPrecedenceAspect)", // 8
"beforeAdviceTwo(lowPrecedenceAspect)", // 9, before proceed
"aroundAdviceOne(lowPrecedenceAspect)", // 10, before proceed
"aroundAdviceTwo(lowPrecedenceAspect)", // 11, after proceed
"aroundAdviceTwo(lowPrecedenceAspect)", // 12, after proceed
"aroundAdviceOne(lowPrecedenceAspect)", // 13
"afterAdviceOne(lowPrecedenceAspect)", // 14
"afterAdviceTwo(lowPrecedenceAspect)", // 15, after proceed
"aroundAdviceTwo(highPrecedenceAspect)", // 16, after proceed
"aroundAdviceOne(highPrecedenceAspect)", // 17
"afterAdviceOne(highPrecedenceAspect)", // 18
"afterAdviceTwo(highPrecedenceAspect)" };
private int adviceInvocationNumber = 0;
private void checkAdvice(String whatJustHappened) {
// System.out.println("[" + adviceInvocationNumber + "] " + whatJustHappened + " ==> " + EXPECTED[adviceInvocationNumber]);
if (adviceInvocationNumber > (EXPECTED.length - 1)) {
fail("Too many advice invocations, expecting " + EXPECTED.length + " but had " + adviceInvocationNumber);
}
String expecting = EXPECTED[adviceInvocationNumber++];
if (!whatJustHappened.equals(expecting)) {
fail("Expecting '" + expecting + "' on advice invocation " + adviceInvocationNumber + " but got '" + whatJustHappened + "'");
}
}
@Override
public void beforeAdviceOne(String beanName) {
checkAdvice("beforeAdviceOne(" + beanName + ")");
}
@Override
public void beforeAdviceTwo(String beanName) {
checkAdvice("beforeAdviceTwo(" + beanName + ")");
}
@Override
public void aroundAdviceOne(String beanName) {
checkAdvice("aroundAdviceOne(" + beanName + ")");
}
@Override
public void aroundAdviceTwo(String beanName) {
checkAdvice("aroundAdviceTwo(" + beanName + ")");
}
@Override
public void afterAdviceOne(String beanName) {
checkAdvice("afterAdviceOne(" + beanName + ")");
}
@Override
public void afterAdviceTwo(String beanName) {
checkAdvice("afterAdviceTwo(" + beanName + ")");
}
}
}
19
Source : AfterThrowingAdviceBindingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Tests for various parameter binding scenarios with before advice.
*
* @author Adrian Colyer
* @author Chris Beams
*/
public clreplaced AfterThrowingAdviceBindingTests {
private ITestBean testBean;
private AfterThrowingAdviceBindingTestAspect afterThrowingAdviceAspect;
private AfterThrowingAdviceBindingCollaborator mockCollaborator;
@Before
public void setup() {
ClreplacedPathXmlApplicationContext ctx = new ClreplacedPathXmlApplicationContext(getClreplaced().getSimpleName() + ".xml", getClreplaced());
testBean = (ITestBean) ctx.getBean("testBean");
afterThrowingAdviceAspect = (AfterThrowingAdviceBindingTestAspect) ctx.getBean("testAspect");
mockCollaborator = mock(AfterThrowingAdviceBindingCollaborator.clreplaced);
afterThrowingAdviceAspect.setCollaborator(mockCollaborator);
}
@Test(expected = Throwable.clreplaced)
public void testSimpleAfterThrowing() throws Throwable {
this.testBean.exceptional(new Throwable());
verify(mockCollaborator).noArgs();
}
@Test(expected = Throwable.clreplaced)
public void testAfterThrowingWithBinding() throws Throwable {
Throwable t = new Throwable();
this.testBean.exceptional(t);
verify(mockCollaborator).oneThrowable(t);
}
@Test(expected = Throwable.clreplaced)
public void testAfterThrowingWithNamedTypeRestriction() throws Throwable {
Throwable t = new Throwable();
this.testBean.exceptional(t);
verify(mockCollaborator).noArgs();
verify(mockCollaborator).oneThrowable(t);
verify(mockCollaborator).noArgsOnThrowableMatch();
}
@Test(expected = Throwable.clreplaced)
public void testAfterThrowingWithRuntimeExceptionBinding() throws Throwable {
RuntimeException ex = new RuntimeException();
this.testBean.exceptional(ex);
verify(mockCollaborator).oneRuntimeException(ex);
}
@Test(expected = Throwable.clreplaced)
public void testAfterThrowingWithTypeSpecified() throws Throwable {
this.testBean.exceptional(new Throwable());
verify(mockCollaborator).noArgsOnThrowableMatch();
}
@Test(expected = Throwable.clreplaced)
public void testAfterThrowingWithRuntimeTypeSpecified() throws Throwable {
this.testBean.exceptional(new RuntimeException());
verify(mockCollaborator).noArgsOnRuntimeExceptionMatch();
}
}
19
Source : AfterReturningAdviceBindingTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
public void testBeanArrayArg(ITestBean[] beans) {
getCollaborator().testBeanArrayArg(beans);
}
19
Source : ProxyFactoryTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void testGetsAllInterfaces() throws Exception {
// Extend to get new interface
clreplaced TestBeanSubclreplaced extends TestBean implements Comparable<Object> {
@Override
public int compareTo(Object arg0) {
throw new UnsupportedOperationException("compareTo");
}
}
TestBeanSubclreplaced raw = new TestBeanSubclreplaced();
ProxyFactory factory = new ProxyFactory(raw);
// System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
replacedertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
ITestBean tb = (ITestBean) factory.getProxy();
replacedertThat("Picked up secondary interface", tb, instanceOf(IOther.clreplaced));
raw.setAge(25);
replacedertTrue(tb.getAge() == raw.getAge());
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
Clreplaced<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.clreplaced));
Clreplaced<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
replacedertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
TimeStamped ts = (TimeStamped) factory.getProxy();
replacedertTrue(ts.getTimeStamp() == t);
// Shouldn't fail;
((IOther) ts).absquatulate();
}
See More Examples