Search in sources :

Example 16 with ExpectedLookupTemplate

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

the class JndiObjectFactoryBeanTests method testLookupWithShortNameAndResourceRefFalse.

@Test
public void testLookupWithShortNameAndResourceRefFalse() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    Object o = new Object();
    jof.setJndiTemplate(new ExpectedLookupTemplate("java:comp/env/foo", o));
    jof.setJndiName("foo");
    jof.setResourceRef(false);
    assertThatExceptionOfType(NamingException.class).isThrownBy(jof::afterPropertiesSet);
}
Also used : ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) NamingException(javax.naming.NamingException) Test(org.junit.jupiter.api.Test)

Example 17 with ExpectedLookupTemplate

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

the class JndiObjectFactoryBeanTests method testLookupWithSchemeNameAndResourceRefTrue.

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

Example 18 with ExpectedLookupTemplate

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

the class JndiObjectFactoryBeanTests method testLookupWithDefaultObjectAndExpectedTypeNoMatch.

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

Example 19 with ExpectedLookupTemplate

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

the class JndiObjectFactoryBeanTests method testLookupWithFullNameAndResourceRefTrue.

@Test
public void testLookupWithFullNameAndResourceRefTrue() 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(true);
    jof.afterPropertiesSet();
    assertThat(jof.getObject() == o).isTrue();
}
Also used : ExpectedLookupTemplate(org.springframework.context.testfixture.jndi.ExpectedLookupTemplate) Test(org.junit.jupiter.api.Test)

Example 20 with ExpectedLookupTemplate

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

the class JndiObjectFactoryBeanTests method testLookupWithShortNameAndResourceRefTrue.

@Test
public void testLookupWithShortNameAndResourceRefTrue() throws Exception {
    JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
    Object o = new Object();
    jof.setJndiTemplate(new ExpectedLookupTemplate("java:comp/env/foo", o));
    jof.setJndiName("foo");
    jof.setResourceRef(true);
    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