use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testConfigMixin.
@Test
void testConfigMixin() {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
PoolingConfig conf = (PoolingConfig) beanFactory.getBean("pooledWithMixin");
// TODO one invocation from setup
// assertEquals(1, conf.getInvocations());
pooled.doWork();
// assertEquals("No objects active", 0, conf.getActive());
assertThat(conf.getMaxSize()).as("Correct target source").isEqualTo(25);
// assertTrue("Some free", conf.getFree() > 0);
// assertEquals(2, conf.getInvocations());
assertThat(conf.getMaxSize()).isEqualTo(25);
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeInstancesAreIndependent.
/**
* Uses its own bean factory XML for clarity
* @param beanName name of the ProxyFactoryBean definition that should
* be a prototype
*/
private Object testPrototypeInstancesAreIndependent(String beanName) {
// Initial count value set in bean factory XML
int INITIAL_COUNT = 10;
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS));
// Check it works without AOP
SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT);
raw.doWork();
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT + 1);
raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT);
// Now try with advised instances
SideEffectBean prototype2FirstInstance = (SideEffectBean) bf.getBean(beanName);
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT);
prototype2FirstInstance.doWork();
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT + 1);
SideEffectBean prototype2SecondInstance = (SideEffectBean) bf.getBean(beanName);
assertThat(prototype2FirstInstance == prototype2SecondInstance).as("Prototypes are not ==").isFalse();
assertThat(prototype2SecondInstance.getCount()).isEqualTo(INITIAL_COUNT);
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT + 1);
return prototype2FirstInstance;
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class HotSwappableTargetSourceTests method testBasicFunctionality.
/**
* Check it works like a normal invoker
*/
@Test
public void testBasicFunctionality() {
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertThat(proxied.getCount()).isEqualTo(INITIAL_COUNT);
proxied.doWork();
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
proxied = (SideEffectBean) beanFactory.getBean("swappable");
proxied.doWork();
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 2));
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testUseDifferentManagedInstancesInSameThread.
/**
* Check we can use two different ThreadLocalTargetSources
* managing objects of different types without them interfering
* with one another.
*/
@Test
public void testUseDifferentManagedInstancesInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
assertThat(test.getName()).isEqualTo("Rod");
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
}
use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testCanGetStatsViaMixin.
/**
* Relies on introduction.
*/
@Test
public void testCanGetStatsViaMixin() {
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
// +1 because creating target for stats call counts
assertThat(stats.getInvocationCount()).isEqualTo(1);
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
apartment.doWork();
// +1 again
assertThat(stats.getInvocationCount()).isEqualTo(3);
// + 1 for states call!
assertThat(stats.getHitCount()).isEqualTo(3);
apartment.doWork();
assertThat(stats.getInvocationCount()).isEqualTo(6);
assertThat(stats.getHitCount()).isEqualTo(6);
// Only one thread so only one object can have been bound
assertThat(stats.getObjectCount()).isEqualTo(1);
}
Aggregations