org.pojava.persistence.jndi
Class TestingContext

java.lang.Object
  extended by org.pojava.persistence.jndi.TestingContext
All Implemented Interfaces:
Context

public class TestingContext
extends Object
implements Context

An implementation of a Context for the purpose of unit testing. Useful for constructing a basic InitialContext that is similar enough to the one provided by Tomcat (for example) to test code that depends upon the existence of an InitialContext. This Context supports binding and the creation and use of subcontexts. For basic stuff like registering a DataSource or Environment variable similar to one provided by server.xml, it should work exactly as expected. This is not a full implementation of a Context and will break down for certain operations involving subcontexts. Most notably, a subcontext returned by a lookup(...) will yield a snapshot view that is only partially synchronized with its parent context. It supports only a one-way relationship where changes to the subcontext are visible to the parent, but not the other way around.

Author:
John Pile

Field Summary
 
Fields inherited from interface javax.naming.Context
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
 
Constructor Summary
TestingContext()
           
 
Method Summary
 Object addToEnvironment(String propName, Object propVal)
           
 void bind(Name name, Object obj)
          Register an object under a specific name.
 void bind(String name, Object obj)
          Register an object under a specific name.
 void close()
           
 Name composeName(Name name, Name prefix)
           
 String composeName(String name, String prefix)
           
 Context createSubcontext(Name name)
           
 Context createSubcontext(String name)
           
 void destroySubcontext(Name name)
           
 void destroySubcontext(String name)
           
 Hashtable<String,Object> getEnvironment()
           
 String getNameInNamespace()
           
 NameParser getNameParser(Name name)
           
 NameParser getNameParser(String name)
           
 NamingEnumeration<NameClassPair> list(Name name)
           
 NamingEnumeration<NameClassPair> list(String name)
           
 NamingEnumeration<Binding> listBindings(Name name)
           
 NamingEnumeration<Binding> listBindings(String name)
           
 Object lookup(Name name)
          Retrieve an object registered under a specific name.
 Object lookup(String name)
          Retrieve an object registered under a specific name.
 Object lookupLink(Name name)
           
 Object lookupLink(String name)
           
 void rebind(Name name, Object obj)
           
 void rebind(String name, Object obj)
           
 Object removeFromEnvironment(String propName)
           
 void rename(Name oldName, Name newName)
          This synchronizes a parent from any child, but not the other way around.
 void rename(String oldName, String newName)
          This synchronizes a parent from any child, but not the other way around.
 void unbind(Name name)
          This synchronizes a parent from any child, but not the other way around.
 void unbind(String name)
          This synchronizes a parent from any child, but not the other way around.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestingContext

public TestingContext()
Method Detail

addToEnvironment

public Object addToEnvironment(String propName,
                               Object propVal)
                        throws NamingException
Specified by:
addToEnvironment in interface Context
Throws:
NamingException

bind

public void bind(Name name,
                 Object obj)
          throws NamingException
Register an object under a specific name. This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
bind in interface Context
Throws:
NamingException

bind

public void bind(String name,
                 Object obj)
          throws NamingException
Register an object under a specific name. This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
bind in interface Context
Throws:
NamingException

close

public void close()
           throws NamingException
Specified by:
close in interface Context
Throws:
NamingException

composeName

public Name composeName(Name name,
                        Name prefix)
                 throws NamingException
Specified by:
composeName in interface Context
Throws:
NamingException

composeName

public String composeName(String name,
                          String prefix)
                   throws NamingException
Specified by:
composeName in interface Context
Throws:
NamingException

createSubcontext

public Context createSubcontext(Name name)
                         throws NamingException
Specified by:
createSubcontext in interface Context
Throws:
NamingException

createSubcontext

public Context createSubcontext(String name)
                         throws NamingException
Specified by:
createSubcontext in interface Context
Throws:
NamingException

destroySubcontext

public void destroySubcontext(Name name)
                       throws NamingException
Specified by:
destroySubcontext in interface Context
Throws:
NamingException

destroySubcontext

public void destroySubcontext(String name)
                       throws NamingException
Specified by:
destroySubcontext in interface Context
Throws:
NamingException

getEnvironment

public Hashtable<String,Object> getEnvironment()
                                        throws NamingException
Specified by:
getEnvironment in interface Context
Throws:
NamingException

getNameInNamespace

public String getNameInNamespace()
                          throws NamingException
Specified by:
getNameInNamespace in interface Context
Throws:
NamingException

getNameParser

public NameParser getNameParser(Name name)
                         throws NamingException
Specified by:
getNameParser in interface Context
Throws:
NamingException

getNameParser

public NameParser getNameParser(String name)
                         throws NamingException
Specified by:
getNameParser in interface Context
Throws:
NamingException

list

public NamingEnumeration<NameClassPair> list(Name name)
                                      throws NamingException
Specified by:
list in interface Context
Throws:
NamingException

list

public NamingEnumeration<NameClassPair> list(String name)
                                      throws NamingException
Specified by:
list in interface Context
Throws:
NamingException

listBindings

public NamingEnumeration<Binding> listBindings(Name name)
                                        throws NamingException
Specified by:
listBindings in interface Context
Throws:
NamingException

listBindings

public NamingEnumeration<Binding> listBindings(String name)
                                        throws NamingException
Specified by:
listBindings in interface Context
Throws:
NamingException

lookup

public Object lookup(Name name)
              throws NamingException
Retrieve an object registered under a specific name.

Specified by:
lookup in interface Context
Throws:
NamingException

lookup

public Object lookup(String name)
              throws NamingException
Retrieve an object registered under a specific name. This shortcuts some of the work necessary to support more complex and mature implementations by returning only a snapshot of the requested subcontext. It's likely good enough to do everything we need for unit testing, but not good enough to serve as a production implementation of a Context.

Specified by:
lookup in interface Context
Throws:
NamingException

lookupLink

public Object lookupLink(Name name)
                  throws NamingException
Specified by:
lookupLink in interface Context
Throws:
NamingException

lookupLink

public Object lookupLink(String name)
                  throws NamingException
Specified by:
lookupLink in interface Context
Throws:
NamingException

rebind

public void rebind(Name name,
                   Object obj)
            throws NamingException
Specified by:
rebind in interface Context
Throws:
NamingException

rebind

public void rebind(String name,
                   Object obj)
            throws NamingException
Specified by:
rebind in interface Context
Throws:
NamingException

removeFromEnvironment

public Object removeFromEnvironment(String propName)
                             throws NamingException
Specified by:
removeFromEnvironment in interface Context
Throws:
NamingException

rename

public void rename(Name oldName,
                   Name newName)
            throws NamingException
This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
rename in interface Context
Throws:
NamingException

rename

public void rename(String oldName,
                   String newName)
            throws NamingException
This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
rename in interface Context
Throws:
NamingException

unbind

public void unbind(Name name)
            throws NamingException
This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
unbind in interface Context
Throws:
NamingException

unbind

public void unbind(String name)
            throws NamingException
This synchronizes a parent from any child, but not the other way around. Good enough for our purposes... just be aware of the limitation.

Specified by:
unbind in interface Context
Throws:
NamingException


Copyright © 2011. All Rights Reserved.