NIHVIVO-1229 Create the RevisionInfoBean, with setup listener and unit tests.
This commit is contained in:
parent
bc86f50c5b
commit
b438f7d36d
6 changed files with 860 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
package stubs.javax.servlet;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
@ -19,7 +20,6 @@ import javax.servlet.ServletException;
|
|||
/**
|
||||
* A simple stand-in for the {@link ServletContext}, for use in unit tests.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ServletContextStub implements ServletContext {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -27,6 +27,18 @@ public class ServletContextStub implements ServletContext {
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
private final Map<String, String> mockResources = new HashMap<String, String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
|
@ -56,6 +68,15 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String path) {
|
||||
if (mockResources.containsKey(path)) {
|
||||
return new ByteArrayInputStream(mockResources.get(path).getBytes());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -79,7 +100,7 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getInitParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getInitParameterNames() not implemented.");
|
||||
|
@ -128,13 +149,7 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourceAsStream() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set getResourcePaths(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getResourcePaths() not implemented.");
|
||||
|
@ -159,14 +174,14 @@ public class ServletContextStub implements ServletContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServletNames() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServletNames() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getServlets() {
|
||||
throw new RuntimeException(
|
||||
"ServletContextStub.getServlets() not implemented.");
|
||||
|
|
132
webapp/test/stubs/javax/servlet/http/HttpSessionStub.java
Normal file
132
webapp/test/stubs/javax/servlet/http/HttpSessionStub.java
Normal file
|
@ -0,0 +1,132 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.javax.servlet.http;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* A simple stand-in for the HttpSession, for use in unit tests.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class HttpSessionStub implements HttpSession {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private ServletContext context;
|
||||
|
||||
public void setServletContext(ServletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getAttribute() not implemented.");
|
||||
}
|
||||
|
||||
@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 String getId() {
|
||||
throw new RuntimeException("HttpSessionStub.getId() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastAccessedTime() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getLastAccessedTime() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInactiveInterval() {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.getMaxInactiveInterval() not implemented.");
|
||||
}
|
||||
|
||||
@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 removeAttribute(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.removeAttribute() not implemented.");
|
||||
}
|
||||
|
||||
public void removeValue(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.removeValue() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String arg0, Object arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.setAttribute() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxInactiveInterval(int arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpSessionStub.setMaxInactiveInterval() not implemented.");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue