|
|
|
@ -16,12 +16,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.jndi; |
|
|
|
package org.springframework.jndi; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.easymock.EasyMock.*; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.NamingException; |
|
|
|
import javax.naming.NamingException; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
import org.junit.Test; |
|
|
|
import org.easymock.MockControl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.DerivedTestBean; |
|
|
|
import org.springframework.beans.DerivedTestBean; |
|
|
|
import org.springframework.beans.ITestBean; |
|
|
|
import org.springframework.beans.ITestBean; |
|
|
|
import org.springframework.beans.TestBean; |
|
|
|
import org.springframework.beans.TestBean; |
|
|
|
@ -30,9 +31,11 @@ import org.springframework.mock.jndi.ExpectedLookupTemplate; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @author Chris Beams |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
public class JndiObjectFactoryBeanTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNoJndiName() throws NamingException { |
|
|
|
public void testNoJndiName() throws NamingException { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -43,6 +46,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithFullNameAndResourceRefTrue() throws Exception { |
|
|
|
public void testLookupWithFullNameAndResourceRefTrue() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -53,6 +57,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithFullNameAndResourceRefFalse() throws Exception { |
|
|
|
public void testLookupWithFullNameAndResourceRefFalse() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -63,6 +68,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithSchemeNameAndResourceRefTrue() throws Exception { |
|
|
|
public void testLookupWithSchemeNameAndResourceRefTrue() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -73,6 +79,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithSchemeNameAndResourceRefFalse() throws Exception { |
|
|
|
public void testLookupWithSchemeNameAndResourceRefFalse() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -83,6 +90,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithShortNameAndResourceRefTrue() throws Exception { |
|
|
|
public void testLookupWithShortNameAndResourceRefTrue() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -93,6 +101,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithShortNameAndResourceRefFalse() throws Exception { |
|
|
|
public void testLookupWithShortNameAndResourceRefFalse() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -108,6 +117,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithArbitraryNameAndResourceRefFalse() throws Exception { |
|
|
|
public void testLookupWithArbitraryNameAndResourceRefFalse() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -118,6 +128,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
assertTrue(jof.getObject() == o); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithExpectedTypeAndMatch() throws Exception { |
|
|
|
public void testLookupWithExpectedTypeAndMatch() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
String s = ""; |
|
|
|
String s = ""; |
|
|
|
@ -128,6 +139,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertTrue(jof.getObject() == s); |
|
|
|
assertTrue(jof.getObject() == s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithExpectedTypeAndNoMatch() throws Exception { |
|
|
|
public void testLookupWithExpectedTypeAndNoMatch() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
@ -143,6 +155,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithDefaultObject() throws Exception { |
|
|
|
public void testLookupWithDefaultObject() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
String s = ""; |
|
|
|
String s = ""; |
|
|
|
@ -154,6 +167,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals("myString", jof.getObject()); |
|
|
|
assertEquals("myString", jof.getObject()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithDefaultObjectAndExpectedType() throws Exception { |
|
|
|
public void testLookupWithDefaultObjectAndExpectedType() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
String s = ""; |
|
|
|
String s = ""; |
|
|
|
@ -165,6 +179,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals("myString", jof.getObject()); |
|
|
|
assertEquals("myString", jof.getObject()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithDefaultObjectAndExpectedTypeNoMatch() throws Exception { |
|
|
|
public void testLookupWithDefaultObjectAndExpectedTypeNoMatch() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
String s = ""; |
|
|
|
String s = ""; |
|
|
|
@ -181,6 +196,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterface() throws Exception { |
|
|
|
public void testLookupWithProxyInterface() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
@ -195,6 +211,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterfaceAndDefaultObject() throws Exception { |
|
|
|
public void testLookupWithProxyInterfaceAndDefaultObject() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
@ -211,6 +228,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterfaceAndLazyLookup() throws Exception { |
|
|
|
public void testLookupWithProxyInterfaceAndLazyLookup() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
@ -236,6 +254,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterfaceWithNotCache() throws Exception { |
|
|
|
public void testLookupWithProxyInterfaceWithNotCache() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
@ -263,6 +282,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals(4, tb.getAge()); |
|
|
|
assertEquals(4, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterfaceWithLazyLookupAndNotCache() throws Exception { |
|
|
|
public void testLookupWithProxyInterfaceWithLazyLookupAndNotCache() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
final TestBean tb = new TestBean(); |
|
|
|
@ -294,6 +314,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals(4, tb.getAge()); |
|
|
|
assertEquals(4, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLazyLookupWithoutProxyInterface() throws NamingException { |
|
|
|
public void testLazyLookupWithoutProxyInterface() throws NamingException { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
jof.setJndiName("foo"); |
|
|
|
jof.setJndiName("foo"); |
|
|
|
@ -307,6 +328,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNotCacheWithoutProxyInterface() throws NamingException { |
|
|
|
public void testNotCacheWithoutProxyInterface() throws NamingException { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
jof.setJndiName("foo"); |
|
|
|
jof.setJndiName("foo"); |
|
|
|
@ -321,6 +343,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithProxyInterfaceAndExpectedTypeAndMatch() throws Exception { |
|
|
|
public void testLookupWithProxyInterfaceAndExpectedTypeAndMatch() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
@ -336,7 +359,8 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testLookupWithProxyInterfaceAndExpectedTypeAndNoMatch() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void testLookupWithProxyInterfaceAndExpectedTypeAndNoMatch() { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb)); |
|
|
|
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb)); |
|
|
|
@ -352,16 +376,15 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testLookupWithExposeAccessContext() throws Exception { |
|
|
|
public void testLookupWithExposeAccessContext() throws Exception { |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
JndiObjectFactoryBean jof = new JndiObjectFactoryBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
MockControl ctxControl = MockControl.createControl(Context.class); |
|
|
|
final Context mockCtx = createMock(Context.class); |
|
|
|
final Context mockCtx = (Context) ctxControl.getMock(); |
|
|
|
expect(mockCtx.lookup("foo")).andReturn(tb); |
|
|
|
mockCtx.lookup("foo"); |
|
|
|
|
|
|
|
ctxControl.setReturnValue(tb); |
|
|
|
|
|
|
|
mockCtx.close(); |
|
|
|
mockCtx.close(); |
|
|
|
ctxControl.setVoidCallable(2); |
|
|
|
expectLastCall().times(2); |
|
|
|
ctxControl.replay(); |
|
|
|
replay(mockCtx); |
|
|
|
jof.setJndiTemplate(new JndiTemplate() { |
|
|
|
jof.setJndiTemplate(new JndiTemplate() { |
|
|
|
protected Context createInitialContext() { |
|
|
|
protected Context createInitialContext() { |
|
|
|
return mockCtx; |
|
|
|
return mockCtx; |
|
|
|
@ -379,7 +402,7 @@ public class JndiObjectFactoryBeanTests extends TestCase { |
|
|
|
proxy.equals(proxy); |
|
|
|
proxy.equals(proxy); |
|
|
|
proxy.hashCode(); |
|
|
|
proxy.hashCode(); |
|
|
|
proxy.toString(); |
|
|
|
proxy.toString(); |
|
|
|
ctxControl.verify(); |
|
|
|
verify(mockCtx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |