类 ExpectedLookupTemplate
- java.lang.Object
- org.springframework.jndi.JndiTemplate
- org.springframework.mock.jndi.ExpectedLookupTemplate
public class ExpectedLookupTemplate extends JndiTemplate
Simple extension of the JndiTemplate class that always returns a given object.Very useful for testing. Effectively a mock object.
- 作者:
- Rod Johnson, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.jndi.JndiTemplate
logger
构造器概要
构造器 构造器 说明 ExpectedLookupTemplate()
Construct a new JndiTemplate that will always return given objects for given names.ExpectedLookupTemplate(String name, Object object)
Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addObject(String name, Object object)
Add the given object to the list of JNDI objects that this template will expose.Object
lookup(String name)
If the name is the expected name specified in the constructor, return the object provided in the constructor.从类继承的方法 org.springframework.jndi.JndiTemplate
bind, createInitialContext, execute, getContext, getEnvironment, lookup, rebind, releaseContext, setEnvironment, unbind
构造器详细资料
ExpectedLookupTemplate
public ExpectedLookupTemplate()
Construct a new JndiTemplate that will always return given objects for given names. To be populated throughaddObject
calls.
ExpectedLookupTemplate
public ExpectedLookupTemplate(String name, Object object)
Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.- 参数:
name
- the name the client is expected to look upobject
- the object that will be returned
方法详细资料
addObject
public void addObject(String name, Object object)
Add the given object to the list of JNDI objects that this template will expose.- 参数:
name
- the name the client is expected to look upobject
- the object that will be returned
lookup
public Object lookup(String name) throws NamingException
If the name is the expected name specified in the constructor, return the object provided in the constructor. If the name is unexpected, a respective NamingException gets thrown.- 覆盖:
lookup
在类中JndiTemplate
- 参数:
name
- the JNDI name of the object- 返回:
- object found (cannot be
null
; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown) - 抛出:
NamingException
- if there is no object with the given name bound to JNDI