Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.mock.jndi
Class 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.

Author:
  Rod Johnson, Juergen Hoeller

Field Summary

Fields inherited from class org.springframework.jndi.JndiTemplate
`logger`

Constructor Summary
`ExpectedLookupTemplate()` Construct a new JndiTemplate that will always return given objects for given names.
`ExpectedLookupTemplate(java.lang.String name, java.lang.Object object)` Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.

Method Summary
`void` | `addObject(java.lang.String name, java.lang.Object object)` Add the given object to the list of JNDI objects that this template will expose.
`java.lang.Object` | `lookup(java.lang.String name)` If the name is the expected name specified in the constructor, return the object provided in the constructor.

Methods inherited from class org.springframework.jndi.JndiTemplate
`bind, createInitialContext, execute, getContext, getEnvironment, lookup, rebind, releaseContext, setEnvironment, unbind`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ExpectedLookupTemplate

    public ExpectedLookupTemplate()

  Construct a new JndiTemplate that will always return given objects for given names. To be populated through `addObject` calls.

  See Also:
    `addObject(String, Object)`

### ExpectedLookupTemplate

    public ExpectedLookupTemplate(java.lang.String name,
                                  java.lang.Object object)

  Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.

  Parameters:
    `name` - the name the client is expected to look up
    `object` - the object that will be returned

Method Detail

### addObject

    public void addObject(java.lang.String name,
                          java.lang.Object object)

  Add the given object to the list of JNDI objects that this template will expose.

  Parameters:
    `name` - the name the client is expected to look up
    `object` - the object that will be returned

### lookup

    public java.lang.Object lookup(java.lang.String name)
                            throws javax.naming.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.

  Overrides:
    `lookup` in class `JndiTemplate`
  Parameters:
    `name` - the JNDI name of the object
  Returns:
    object found (cannot be `null`; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
  Throws:
    `javax.naming.NamingException` - if there is no object with the given name bound to JNDI

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD