Normalize line endings VIVO-101
This commit is contained in:
parent
b097a4d754
commit
54f79f2ea7
587 changed files with 91501 additions and 91501 deletions
|
@ -1,219 +1,219 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*/
|
||||
public class ContextStub implements Context {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Keep a single context instance for each path.
|
||||
*/
|
||||
private static final Map<String, ContextStub> instances = new HashMap<String, ContextStub>();
|
||||
|
||||
/**
|
||||
* Get the context instance for this path. Create one if necessary.
|
||||
*/
|
||||
static ContextStub getInstance(String contextPath, InitialContextStub parent) {
|
||||
if (!instances.containsKey(contextPath)) {
|
||||
instances.put(contextPath, new ContextStub(contextPath, parent));
|
||||
}
|
||||
return instances.get(contextPath);
|
||||
}
|
||||
|
||||
private final String contextPath;
|
||||
private final InitialContextStub parent;
|
||||
|
||||
private ContextStub(String contextPath, InitialContextStub parent) {
|
||||
this.contextPath = contextPath;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Let the parent handle it.
|
||||
*/
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("ContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException("ContextStub: name may not be empty.");
|
||||
}
|
||||
parent.rebind(contextPath + "/" + name, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* In most cases, just let the parent handle it.
|
||||
*/
|
||||
public Object lookup(String name) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NamingException("ContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
return this;
|
||||
}
|
||||
return parent.lookup(contextPath + "/" + name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.addToEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
throw new RuntimeException("ContextStub.close() not implemented.");
|
||||
}
|
||||
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameInNamespace() not implemented.");
|
||||
}
|
||||
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookup() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rebind() not implemented.");
|
||||
}
|
||||
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.removeFromEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
private boolean isEmpty(String string) {
|
||||
return (string == null || string.trim().length() == 0);
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*/
|
||||
public class ContextStub implements Context {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Keep a single context instance for each path.
|
||||
*/
|
||||
private static final Map<String, ContextStub> instances = new HashMap<String, ContextStub>();
|
||||
|
||||
/**
|
||||
* Get the context instance for this path. Create one if necessary.
|
||||
*/
|
||||
static ContextStub getInstance(String contextPath, InitialContextStub parent) {
|
||||
if (!instances.containsKey(contextPath)) {
|
||||
instances.put(contextPath, new ContextStub(contextPath, parent));
|
||||
}
|
||||
return instances.get(contextPath);
|
||||
}
|
||||
|
||||
private final String contextPath;
|
||||
private final InitialContextStub parent;
|
||||
|
||||
private ContextStub(String contextPath, InitialContextStub parent) {
|
||||
this.contextPath = contextPath;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Let the parent handle it.
|
||||
*/
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("ContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException("ContextStub: name may not be empty.");
|
||||
}
|
||||
parent.rebind(contextPath + "/" + name, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* In most cases, just let the parent handle it.
|
||||
*/
|
||||
public Object lookup(String name) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NamingException("ContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
return this;
|
||||
}
|
||||
return parent.lookup(contextPath + "/" + name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.addToEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
throw new RuntimeException("ContextStub.close() not implemented.");
|
||||
}
|
||||
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameInNamespace() not implemented.");
|
||||
}
|
||||
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("ContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookup() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rebind() not implemented.");
|
||||
}
|
||||
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"ContextStub.removeFromEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new RuntimeException("ContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
private boolean isEmpty(String string) {
|
||||
return (string == null || string.trim().length() == 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,308 +1,308 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*
|
||||
* The bindings are static, so you will probablly want to call {@link #reset()}
|
||||
* before each test.
|
||||
*/
|
||||
public class InitialContextStub extends InitialContext {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Map<String, Object> bindings = new TreeMap<String, Object>();
|
||||
|
||||
/**
|
||||
* Make sure we start the next test with a fresh instance.
|
||||
*/
|
||||
public static void reset() {
|
||||
bindings.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have properties that are bound to a level below this name, then
|
||||
* this name represents a sub-context.
|
||||
*/
|
||||
private boolean isSubContext(String name) {
|
||||
String path = name.endsWith("/") ? name : name + "/";
|
||||
|
||||
for (String key : bindings.keySet()) {
|
||||
if (key.startsWith(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public InitialContextStub() throws NamingException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Hashtable<?, ?> environment) throws NamingException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getURLOrDefaultInitCtx(String name)
|
||||
throws NamingException {
|
||||
return super.getURLOrDefaultInitCtx(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getDefaultInitCtx() throws NamingException {
|
||||
return ContextStub.getInstance("", this);
|
||||
}
|
||||
|
||||
private boolean isEmpty(String string) {
|
||||
return (string == null || string.trim().length() == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name may not be empty.");
|
||||
}
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name is already bound.");
|
||||
}
|
||||
|
||||
bindings.put(name, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name may not be empty.");
|
||||
}
|
||||
|
||||
bindings.put(name, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(String name) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
return this;
|
||||
}
|
||||
if (bindings.containsKey(name)) {
|
||||
return bindings.get(name);
|
||||
}
|
||||
if (isSubContext(name)) {
|
||||
return ContextStub.getInstance(name, this);
|
||||
}
|
||||
|
||||
throw new NamingException("InitialContextStub: No binding for '" + name
|
||||
+ "'");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.addToEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.close() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameInNamespace() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getURLOrDefaultInitCtx() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookup() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rebind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.removeFromEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*
|
||||
* The bindings are static, so you will probablly want to call {@link #reset()}
|
||||
* before each test.
|
||||
*/
|
||||
public class InitialContextStub extends InitialContext {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Map<String, Object> bindings = new TreeMap<String, Object>();
|
||||
|
||||
/**
|
||||
* Make sure we start the next test with a fresh instance.
|
||||
*/
|
||||
public static void reset() {
|
||||
bindings.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have properties that are bound to a level below this name, then
|
||||
* this name represents a sub-context.
|
||||
*/
|
||||
private boolean isSubContext(String name) {
|
||||
String path = name.endsWith("/") ? name : name + "/";
|
||||
|
||||
for (String key : bindings.keySet()) {
|
||||
if (key.startsWith(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public InitialContextStub() throws NamingException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Hashtable<?, ?> environment) throws NamingException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getURLOrDefaultInitCtx(String name)
|
||||
throws NamingException {
|
||||
return super.getURLOrDefaultInitCtx(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getDefaultInitCtx() throws NamingException {
|
||||
return ContextStub.getInstance("", this);
|
||||
}
|
||||
|
||||
private boolean isEmpty(String string) {
|
||||
return (string == null || string.trim().length() == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name may not be empty.");
|
||||
}
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name is already bound.");
|
||||
}
|
||||
|
||||
bindings.put(name, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null.");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
throw new NamingException(
|
||||
"InitialContextStub: name may not be empty.");
|
||||
}
|
||||
|
||||
bindings.put(name, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(String name) throws NamingException {
|
||||
if (name == null) {
|
||||
throw new NullPointerException(
|
||||
"InitialContextStub: name may not be null");
|
||||
}
|
||||
if (isEmpty(name)) {
|
||||
return this;
|
||||
}
|
||||
if (bindings.containsKey(name)) {
|
||||
return bindings.get(name);
|
||||
}
|
||||
if (isSubContext(name)) {
|
||||
return ContextStub.getInstance(name, this);
|
||||
}
|
||||
|
||||
throw new NamingException("InitialContextStub: No binding for '" + name
|
||||
+ "'");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.addToEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.bind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.close() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.composeName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.createSubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.destroySubcontext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hashtable<?, ?> getEnvironment() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameInNamespace() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getNameParser() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.getURLOrDefaultInitCtx() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException("InitialContextStub.list() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.listBindings() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookup() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.lookupLink() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rebind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.removeFromEnvironment() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.rename() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new RuntimeException(
|
||||
"InitialContextStub.unbind() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming.spi;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.spi.InitialContextFactory;
|
||||
|
||||
import stubs.javax.naming.InitialContextStub;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*/
|
||||
public class InitialContextFactoryStub implements InitialContextFactory {
|
||||
/**
|
||||
* It's just this easy.
|
||||
*/
|
||||
public Context getInitialContext(Hashtable<?, ?> environment)
|
||||
throws NamingException {
|
||||
return new InitialContextStub();
|
||||
}
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.naming.spi;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.spi.InitialContextFactory;
|
||||
|
||||
import stubs.javax.naming.InitialContextStub;
|
||||
|
||||
/**
|
||||
* In order to use this and the other naming stubs.javax.naming classes, do
|
||||
* this:
|
||||
*
|
||||
* <pre>
|
||||
* System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
|
||||
* InitialContextFactoryStub.class.getName());
|
||||
* </pre>
|
||||
*/
|
||||
public class InitialContextFactoryStub implements InitialContextFactory {
|
||||
/**
|
||||
* It's just this easy.
|
||||
*/
|
||||
public Context getInitialContext(Hashtable<?, ?> environment)
|
||||
throws NamingException {
|
||||
return new InitialContextStub();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,56 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* A simple stub for testing servlets.
|
||||
*/
|
||||
public class ServletConfigStub implements ServletConfig {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
return servletContext;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getInitParameter() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getInitParameterNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletName() {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getServletName() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* A simple stub for testing servlets.
|
||||
*/
|
||||
public class ServletConfigStub implements ServletConfig {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
return servletContext;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getInitParameter() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getInitParameterNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletName() {
|
||||
throw new RuntimeException(
|
||||
"ServletConfigStub.getServletName() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,243 +1,243 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* A simple stand-in for the {@link ServletContext}, for use in unit tests.
|
||||
*/
|
||||
public class ServletContextStub implements ServletContext {
|
||||
private static final Log log = LogFactory.getLog(ServletContextStub.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String contextPath = ""; // root context returns ""
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
private final Map<String, String> mockResources = new HashMap<String, String>();
|
||||
private final Map<String, String> realPaths = new HashMap<String, String>();
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
if (contextPath == null) {
|
||||
throw new NullPointerException("contextPath may not be null.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setMockResource(String path, String contents) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("path may not be null.");
|
||||
}
|
||||
if (contents == null) {
|
||||
mockResources.remove(path);
|
||||
} else {
|
||||
mockResources.put(path, contents);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRealPath(String path, String filepath) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("path may not be null.");
|
||||
}
|
||||
if (filepath == null) {
|
||||
log.debug("removing real path for '" + path + "'");
|
||||
realPaths.remove(path);
|
||||
} else {
|
||||
log.debug("adding real path for '" + path + "' = '" + filepath
|
||||
+ "'");
|
||||
realPaths.put(path, filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call setRealPath for each of the files in this directory (non-recursive).
|
||||
* The prefix is the "pretend" location that we're mapping these files to,
|
||||
* e.g. "/config/". Use the prefix and the filename as the path.
|
||||
*/
|
||||
public void setRealPaths(String pathPrefix, File dir) {
|
||||
for (File file : dir.listFiles()) {
|
||||
setRealPath(pathPrefix + file.getName(), file.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return Collections.enumeration(attributes.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object object) {
|
||||
if (object == null) {
|
||||
removeAttribute(name);
|
||||
} else {
|
||||
attributes.put(name, object);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String path) {
|
||||
if (mockResources.containsKey(path)) {
|
||||
return new ByteArrayInputStream(mockResources.get(path).getBytes());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRealPath(String path) {
|
||||
String real = realPaths.get(path);
|
||||
log.debug("Real path for '" + path + "' is '" + real + "'");
|
||||
return real;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ServletContext getContext(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getContext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameter() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameterNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMajorVersion() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMimeType(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMimeType() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMinorVersion() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getNamedDispatcher(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getNamedDispatcher() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getRequestDispatcher() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String arg0) throws MalformedURLException {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResource() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set getResourcePaths(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourcePaths() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerInfo() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServerInfo() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Servlet getServlet(String arg0) throws ServletException {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlet() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletContextName() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletContextName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServletNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServlets() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlets() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String arg0) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Exception arg0, String arg1) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String arg0, Throwable arg1) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* A simple stand-in for the {@link ServletContext}, for use in unit tests.
|
||||
*/
|
||||
public class ServletContextStub implements ServletContext {
|
||||
private static final Log log = LogFactory.getLog(ServletContextStub.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String contextPath = ""; // root context returns ""
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
private final Map<String, String> mockResources = new HashMap<String, String>();
|
||||
private final Map<String, String> realPaths = new HashMap<String, String>();
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
if (contextPath == null) {
|
||||
throw new NullPointerException("contextPath may not be null.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setMockResource(String path, String contents) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("path may not be null.");
|
||||
}
|
||||
if (contents == null) {
|
||||
mockResources.remove(path);
|
||||
} else {
|
||||
mockResources.put(path, contents);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRealPath(String path, String filepath) {
|
||||
if (path == null) {
|
||||
throw new NullPointerException("path may not be null.");
|
||||
}
|
||||
if (filepath == null) {
|
||||
log.debug("removing real path for '" + path + "'");
|
||||
realPaths.remove(path);
|
||||
} else {
|
||||
log.debug("adding real path for '" + path + "' = '" + filepath
|
||||
+ "'");
|
||||
realPaths.put(path, filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call setRealPath for each of the files in this directory (non-recursive).
|
||||
* The prefix is the "pretend" location that we're mapping these files to,
|
||||
* e.g. "/config/". Use the prefix and the filename as the path.
|
||||
*/
|
||||
public void setRealPaths(String pathPrefix, File dir) {
|
||||
for (File file : dir.listFiles()) {
|
||||
setRealPath(pathPrefix + file.getName(), file.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return Collections.enumeration(attributes.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object object) {
|
||||
if (object == null) {
|
||||
removeAttribute(name);
|
||||
} else {
|
||||
attributes.put(name, object);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String path) {
|
||||
if (mockResources.containsKey(path)) {
|
||||
return new ByteArrayInputStream(mockResources.get(path).getBytes());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRealPath(String path) {
|
||||
String real = realPaths.get(path);
|
||||
log.debug("Real path for '" + path + "' is '" + real + "'");
|
||||
return real;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ServletContext getContext(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getContext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameter() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameterNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMajorVersion() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMimeType(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMimeType() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getMinorVersion() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getNamedDispatcher(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getNamedDispatcher() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getRequestDispatcher() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String arg0) throws MalformedURLException {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResource() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set getResourcePaths(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourcePaths() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerInfo() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServerInfo() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Servlet getServlet(String arg0) throws ServletException {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlet() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletContextName() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletContextName() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServletNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServlets() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlets() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String arg0) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Exception arg0, String arg1) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String arg0, Throwable arg1) {
|
||||
throw new RuntimeException("ServletContextStub.log() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,289 +1,289 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet.http;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* A simple stub for HttpServletResponse
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class HttpServletResponseStub implements HttpServletResponse {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String redirectLocation;
|
||||
private int status = 200;
|
||||
private String errorMessage;
|
||||
private Map<String, String> headers = new HashMap<String, String>();
|
||||
private String contentType;
|
||||
private String charset = "";
|
||||
|
||||
private ByteArrayOutputStream outputStream;
|
||||
private StringWriter outputWriter;
|
||||
|
||||
public String getRedirectLocation() {
|
||||
return redirectLocation;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public String getOutput() {
|
||||
if (outputStream != null) {
|
||||
return outputStream.toString();
|
||||
} else if (outputWriter != null) {
|
||||
return outputWriter.toString();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getHeader(String name) {
|
||||
return headers.get(name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void sendRedirect(String location) throws IOException {
|
||||
this.redirectLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("hiding")
|
||||
public void sendError(int status) throws IOException {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("hiding")
|
||||
public void sendError(int status, String message) throws IOException {
|
||||
this.status = status;
|
||||
this.errorMessage = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getWriter() throws IOException {
|
||||
if (outputStream != null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't get a Writer after getting an OutputStream.");
|
||||
}
|
||||
|
||||
if (outputWriter == null) {
|
||||
outputWriter = new StringWriter();
|
||||
}
|
||||
|
||||
return new PrintWriter(outputWriter, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletOutputStream getOutputStream() throws IOException {
|
||||
if (outputWriter != null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't get an OutputStream after getting a Writer.");
|
||||
}
|
||||
|
||||
if (outputStream == null) {
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
return new ServletOutputStream() {
|
||||
@Override
|
||||
public void write(int thisChar) throws IOException {
|
||||
outputStream.write(thisChar);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsHeader(String name) {
|
||||
return headers.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling setContentType("this/type;charset=UTF-8") is the same as calling
|
||||
* setContentType("this/type;charset=UTF-8"); setCharacterEncoding("UTF-8")
|
||||
*/
|
||||
@Override
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
|
||||
Pattern p = Pattern.compile(";\\scharset=([^;]+)");
|
||||
Matcher m = p.matcher(contentType);
|
||||
if (m.find()) {
|
||||
this.charset = m.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterEncoding(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharacterEncoding() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void flushBuffer() throws IOException {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.flushBuffer() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferSize() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.getBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.getLocale() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommitted() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.isCommitted() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.reset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBuffer() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.resetBuffer() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBufferSize(int arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(int arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setContentLength() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(Locale arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setLocale() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCookie(Cookie arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addCookie() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDateHeader(String arg0, long arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addDateHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(String arg0, String arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addIntHeader(String arg0, int arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addIntHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeRedirectURL(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeRedirectURL() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeRedirectUrl(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeRedirectUrl() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeURL(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeURL() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeUrl(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeUrl() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDateHeader(String arg0, long arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setDateHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntHeader(String arg0, int arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setIntHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(int arg0, String arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setStatus() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet.http;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* A simple stub for HttpServletResponse
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class HttpServletResponseStub implements HttpServletResponse {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String redirectLocation;
|
||||
private int status = 200;
|
||||
private String errorMessage;
|
||||
private Map<String, String> headers = new HashMap<String, String>();
|
||||
private String contentType;
|
||||
private String charset = "";
|
||||
|
||||
private ByteArrayOutputStream outputStream;
|
||||
private StringWriter outputWriter;
|
||||
|
||||
public String getRedirectLocation() {
|
||||
return redirectLocation;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public String getOutput() {
|
||||
if (outputStream != null) {
|
||||
return outputStream.toString();
|
||||
} else if (outputWriter != null) {
|
||||
return outputWriter.toString();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getHeader(String name) {
|
||||
return headers.get(name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void sendRedirect(String location) throws IOException {
|
||||
this.redirectLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("hiding")
|
||||
public void sendError(int status) throws IOException {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("hiding")
|
||||
public void sendError(int status, String message) throws IOException {
|
||||
this.status = status;
|
||||
this.errorMessage = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getWriter() throws IOException {
|
||||
if (outputStream != null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't get a Writer after getting an OutputStream.");
|
||||
}
|
||||
|
||||
if (outputWriter == null) {
|
||||
outputWriter = new StringWriter();
|
||||
}
|
||||
|
||||
return new PrintWriter(outputWriter, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletOutputStream getOutputStream() throws IOException {
|
||||
if (outputWriter != null) {
|
||||
throw new IllegalStateException(
|
||||
"Can't get an OutputStream after getting a Writer.");
|
||||
}
|
||||
|
||||
if (outputStream == null) {
|
||||
outputStream = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
return new ServletOutputStream() {
|
||||
@Override
|
||||
public void write(int thisChar) throws IOException {
|
||||
outputStream.write(thisChar);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsHeader(String name) {
|
||||
return headers.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling setContentType("this/type;charset=UTF-8") is the same as calling
|
||||
* setContentType("this/type;charset=UTF-8"); setCharacterEncoding("UTF-8")
|
||||
*/
|
||||
@Override
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
|
||||
Pattern p = Pattern.compile(";\\scharset=([^;]+)");
|
||||
Matcher m = p.matcher(contentType);
|
||||
if (m.find()) {
|
||||
this.charset = m.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterEncoding(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharacterEncoding() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void flushBuffer() throws IOException {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.flushBuffer() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBufferSize() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.getBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.getLocale() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCommitted() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.isCommitted() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.reset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBuffer() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.resetBuffer() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBufferSize(int arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(int arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setContentLength() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(Locale arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setLocale() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCookie(Cookie arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addCookie() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDateHeader(String arg0, long arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addDateHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(String arg0, String arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addIntHeader(String arg0, int arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.addIntHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeRedirectURL(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeRedirectURL() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeRedirectUrl(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeRedirectUrl() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeURL(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeURL() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeUrl(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.encodeUrl() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDateHeader(String arg0, long arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setDateHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntHeader(String arg0, int arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setIntHeader() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(int arg0, String arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setStatus() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,163 +1,163 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet.http;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
|
||||
/**
|
||||
* A simple stand-in for the HttpSession, for use in unit tests.
|
||||
*/
|
||||
public class HttpSessionStub implements HttpSession {
|
||||
private static final Log log = LogFactory.getLog(HttpSessionStub.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String id = "arbitraryId";
|
||||
private ServletContext context;
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int maxInactiveInterval;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setServletContext(ServletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
if (this.context == null) {
|
||||
return new ServletContextStub();
|
||||
} else {
|
||||
return this.context;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name may not be null.");
|
||||
}
|
||||
if (value == null) {
|
||||
removeAttribute(name);
|
||||
}
|
||||
attributes.put(name, value);
|
||||
log.debug("setAttribute: " + name + "=" + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
log.debug("removeAttribute: " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* So far, we don't do anything with this, or even confirm that it has been
|
||||
* set. We just don't throw an exception if someone wants to set it.
|
||||
*/
|
||||
@Override
|
||||
public void setMaxInactiveInterval(int seconds) {
|
||||
this.maxInactiveInterval = seconds;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getAttributeNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getAttributeNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTime() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getCreationTime() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastAccessedTime() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getLastAccessedTime() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInactiveInterval() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getMaxInactiveInterval() not implemented.");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public javax.servlet.http.HttpSessionContext getSessionContext() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getSessionContext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getValue() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValueNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getValueNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.invalidate() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
throw new RuntimeException("HttpSessionStub.isNew() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String arg0, Object arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.putValue() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.removeValue() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet.http;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
|
||||
/**
|
||||
* A simple stand-in for the HttpSession, for use in unit tests.
|
||||
*/
|
||||
public class HttpSessionStub implements HttpSession {
|
||||
private static final Log log = LogFactory.getLog(HttpSessionStub.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private String id = "arbitraryId";
|
||||
private ServletContext context;
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int maxInactiveInterval;
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setServletContext(ServletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
if (this.context == null) {
|
||||
return new ServletContextStub();
|
||||
} else {
|
||||
return this.context;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name may not be null.");
|
||||
}
|
||||
if (value == null) {
|
||||
removeAttribute(name);
|
||||
}
|
||||
attributes.put(name, value);
|
||||
log.debug("setAttribute: " + name + "=" + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
log.debug("removeAttribute: " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* So far, we don't do anything with this, or even confirm that it has been
|
||||
* set. We just don't throw an exception if someone wants to set it.
|
||||
*/
|
||||
@Override
|
||||
public void setMaxInactiveInterval(int seconds) {
|
||||
this.maxInactiveInterval = seconds;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getAttributeNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getAttributeNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreationTime() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getCreationTime() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastAccessedTime() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getLastAccessedTime() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInactiveInterval() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getMaxInactiveInterval() not implemented.");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public javax.servlet.http.HttpSessionContext getSessionContext() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getSessionContext() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getValue() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValueNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getValueNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.invalidate() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
throw new RuntimeException("HttpSessionStub.isNew() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String arg0, Object arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.putValue() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.removeValue() not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue