Search in sources :

Example 21 with ExpectedLookupTemplate

use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class JndiObjectFactoryBeanTests method testLookupWithProxyInterfaceAndDefaultObject.

@Test
public void testLookupWithProxyInterfaceAndDefaultObject() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    TestBean tb = new TestBean();
    jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
    jof.setJndiName("myFoo");
    jof.setProxyInterface(ITestBean.class);
    jof.setDefaultObject(Boolean.TRUE);
    assertThatIllegalArgumentException().isThrownBy(jof::afterPropertiesSet);
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Example 22 with ExpectedLookupTemplate

use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class JndiObjectFactoryBeanTests method testLookupWithDefaultObject.

@Test
public void testLookupWithDefaultObject() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    jof.setJndiTemplate(new ExpectedLookupTemplate("foo", ""));
    jof.setJndiName("myFoo");
    jof.setExpectedType(String.class);
    jof.setDefaultObject("myString");
    jof.afterPropertiesSet();
    assertThat(jof.getObject()).isEqualTo("myString");
}
Also used : ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Example 23 with ExpectedLookupTemplate

use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class JndiObjectFactoryBeanTests method testLookupWithDefaultObjectAndExpectedTypeConversion.

@Test
public void testLookupWithDefaultObjectAndExpectedTypeConversion() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    jof.setJndiTemplate(new ExpectedLookupTemplate("foo", ""));
    jof.setJndiName("myFoo");
    jof.setExpectedType(Integer.class);
    jof.setDefaultObject("5");
    jof.afterPropertiesSet();
    assertThat(jof.getObject()).isEqualTo(5);
}
Also used : ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Example 24 with ExpectedLookupTemplate

use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class JndiObjectFactoryBeanTests method testLookupWithProxyInterfaceAndExpectedTypeAndMatch.

@Test
public void testLookupWithProxyInterfaceAndExpectedTypeAndMatch() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    TestBean tb = new TestBean();
    jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
    jof.setJndiName("foo");
    jof.setExpectedType(TestBean.class);
    jof.setProxyInterface(ITestBean.class);
    jof.afterPropertiesSet();
    boolean condition = jof.getObject() instanceof ITestBean;
    assertThat(condition).isTrue();
    ITestBean proxy = (ITestBean) jof.getObject();
    assertThat(tb.getAge()).isEqualTo(0);
    proxy.setAge(99);
    assertThat(tb.getAge()).isEqualTo(99);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Example 25 with ExpectedLookupTemplate

use of org.springframework.context.testfixture.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class JndiObjectFactoryBeanTests method testLookupWithFullNameAndResourceRefFalse.

@Test
public void testLookupWithFullNameAndResourceRefFalse() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    Object o = new Object();
    jof.setJndiTemplate(new ExpectedLookupTemplate("java:comp/env/foo", o));
    jof.setJndiName("java:comp/env/foo");
    jof.setResourceRef(false);
    jof.afterPropertiesSet();
    assertThat(jof.getObject() == o).isTrue();
}
Also used : ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ExpectedLookupTemplate (org.springframework.context.testfixture.jndi.ExpectedLookupTemplate)28 Test (org.junit.jupiter.api.Test)27 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 HashMap (java.util.HashMap)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)5 TestBean (org.springframework.beans.testfixture.beans.TestBean)5 EntityManager (jakarta.persistence.EntityManager)4 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)4 UserTransaction (jakarta.transaction.UserTransaction)3 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)3 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 TransactionManager (jakarta.transaction.TransactionManager)2 NamingException (javax.naming.NamingException)1 INestedTestBean (org.springframework.beans.testfixture.beans.INestedTestBean)1 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)1 SimpleJndiBeanFactory (org.springframework.jndi.support.SimpleJndiBeanFactory)1 UserTransactionAdapter (org.springframework.transaction.jta.UserTransactionAdapter)1