public class SingletonInitialContext extends Object implements Context
JNDI naming context
that can be used in unit tests for code that
looks up
objects.
This can be used easily in a unit test by either using one of two methods. The first is using the convenient static
configure
method that takes one, two or three name/object pairs:
SingletonInitialContext.register(name, obj); SingletonInitialContext.register(name1, obj1, name2, obj2); SingletonInitialContext.register(name1, obj1, name2, obj2, name3, obj3);
The other approach is to set the system property for the InitialContextFactory
:
System.setProperty("java.naming.factory.initial", "org.modeshape.common.mock.SingletonInitialContextFactory");and then to
bind
an object.SingletonInitialContextFactory
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
public static void register(String name, Object obj)
name
- the JNDI nameobj
- the object to be registeredpublic static void register(String name1, Object obj1, String name2, Object obj2)
name1
- the JNDI name for the first objectobj1
- the first object to be registeredname2
- the JNDI name for the second objectobj2
- the second object to be registeredpublic static void register(String name1, Object obj1, String name2, Object obj2, String name3, Object obj3)
name1
- the JNDI name for the first objectobj1
- the first object to be registeredname2
- the JNDI name for the second objectobj2
- the second object to be registeredname3
- the JNDI name for the third objectobj3
- the third object to be registeredpublic Object addToEnvironment(String propName, Object propVal)
addToEnvironment
in interface Context
public Object removeFromEnvironment(String propName)
removeFromEnvironment
in interface Context
public void bind(Name name, Object obj) throws NamingException
bind
in interface Context
NamingException
public void bind(String name, Object obj) throws NamingException
bind
in interface Context
NamingException
public Object lookup(Name name) throws NamingException
lookup
in interface Context
NamingException
public Object lookup(String name) throws NamingException
lookup
in interface Context
NamingException
public Object lookupLink(String name)
lookupLink
in interface Context
public Object lookupLink(Name name)
lookupLink
in interface Context
public Name composeName(Name name, Name prefix)
composeName
in interface Context
public String composeName(String name, String prefix)
composeName
in interface Context
public Context createSubcontext(Name name)
createSubcontext
in interface Context
public Context createSubcontext(String name)
createSubcontext
in interface Context
public void destroySubcontext(Name name)
destroySubcontext
in interface Context
public void destroySubcontext(String name)
destroySubcontext
in interface Context
public Hashtable<?,?> getEnvironment()
getEnvironment
in interface Context
public String getNameInNamespace()
getNameInNamespace
in interface Context
public NameParser getNameParser(Name name)
getNameParser
in interface Context
public NameParser getNameParser(String name)
getNameParser
in interface Context
public NamingEnumeration<NameClassPair> list(Name name)
public NamingEnumeration<NameClassPair> list(String name)
public NamingEnumeration<Binding> listBindings(Name name)
listBindings
in interface Context
public NamingEnumeration<Binding> listBindings(String name)
listBindings
in interface Context
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.