Search in sources :

Example 6 with SideEffectBean

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);
}
Also used : SideEffectBean(org.springframework.beans.testfixture.beans.SideEffectBean) Test(org.junit.jupiter.api.Test)

Example 7 with SideEffectBean

use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.

the class PrototypeTargetSourceTests method testPrototypeAndSingletonBehaveDifferently.

/**
 * Test that multiple invocations of the prototype bean will result
 * in no change to visible state, as a new instance is used.
 * With the singleton, there will be change.
 */
@Test
public void testPrototypeAndSingletonBehaveDifferently() {
    SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
    assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT);
    singleton.doWork();
    assertThat(singleton.getCount()).isEqualTo((INITIAL_COUNT + 1));
    SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
    assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
    prototype.doWork();
    assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
}
Also used : SideEffectBean(org.springframework.beans.testfixture.beans.SideEffectBean) Test(org.junit.jupiter.api.Test)

Example 8 with SideEffectBean

use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.

the class HotSwappableTargetSourceTests method testValidSwaps.

@Test
public void testValidSwaps() {
    SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
    SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
    SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
    assertThat(proxied.getCount()).isEqualTo(target1.getCount());
    proxied.doWork();
    assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
    HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
    Object old = swapper.swap(target2);
    assertThat(old).as("Correct old target was returned").isEqualTo(target1);
    // TODO should be able to make this assertion: need to fix target handling
    // in AdvisedSupport
    // assertEquals(target2, ((Advised) proxied).getTarget());
    assertThat(proxied.getCount()).isEqualTo(20);
    proxied.doWork();
    assertThat(target2.getCount()).isEqualTo(21);
    // Swap it back
    swapper.swap(target1);
    assertThat(proxied.getCount()).isEqualTo(target1.getCount());
}
Also used : SideEffectBean(org.springframework.beans.testfixture.beans.SideEffectBean) Test(org.junit.jupiter.api.Test)

Example 9 with SideEffectBean

use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.

the class ThreadLocalTargetSourceTests method testReuseInSameThread.

@Test
public void testReuseInSameThread() {
    SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
    assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
    apartment.doWork();
    assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
    apartment = (SideEffectBean) beanFactory.getBean("apartment");
    assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
}
Also used : SideEffectBean(org.springframework.beans.testfixture.beans.SideEffectBean) Test(org.junit.jupiter.api.Test)

Example 10 with SideEffectBean

use of org.springframework.beans.testfixture.beans.SideEffectBean in project spring-framework by spring-projects.

the class CommonsPool2TargetSourceTests method testFunctionality.

private void testFunctionality(String name) {
    SideEffectBean pooled = (SideEffectBean) beanFactory.getBean(name);
    assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
    pooled.doWork();
    assertThat(pooled.getCount()).isEqualTo((INITIAL_COUNT + 1));
    pooled = (SideEffectBean) beanFactory.getBean(name);
    // Just check that it works--we can't make assumptions
    // about the count
    pooled.doWork();
// assertEquals(INITIAL_COUNT + 1, apartment.getCount());
}
Also used : SideEffectBean(org.springframework.beans.testfixture.beans.SideEffectBean)

Aggregations

SideEffectBean (org.springframework.beans.testfixture.beans.SideEffectBean)10 Test (org.junit.jupiter.api.Test)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1