NIHVIVO-3628 Create unit tests to cover the parsing and interpreting of custom list view config files.

This commit is contained in:
j2blake 2012-02-21 17:06:55 +00:00
parent 3ceff9e0a5
commit b53f26a375
26 changed files with 1282 additions and 20 deletions

View file

@ -26,18 +26,32 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
// ----------------------------------------------------------------------
private final Map<String, ObjectProperty> opMap = new HashMap<String, ObjectProperty>();
private final Map<String, String> configFilesMap = new HashMap<String, String>();
public void addObjectProperty(ObjectProperty predicate) {
if (predicate == null) {
public void addObjectProperty(ObjectProperty property) {
if (property == null) {
throw new NullPointerException("predicate may not be null.");
}
String uri = predicate.getURI();
String uri = property.getURI();
if (uri == null) {
throw new NullPointerException("uri may not be null.");
}
opMap.put(uri, predicate);
opMap.put(uri, property);
}
public void setCustomListViewConfigFileName(ObjectProperty property, String filename) {
if (property == null) {
throw new NullPointerException("property may not be null.");
}
String uri = property.getURI();
if (uri == null) {
throw new NullPointerException("uri may not be null.");
}
configFilesMap.put(uri, filename);
}
// ----------------------------------------------------------------------
@ -46,9 +60,24 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
@Override
public ObjectProperty getObjectPropertyByURI(String objectPropertyURI) {
if (objectPropertyURI == null) {
return null;
}
return opMap.get(objectPropertyURI);
}
@Override
public String getCustomListViewConfigFileName(ObjectProperty objectProperty) {
if (objectProperty == null) {
return null;
}
String uri = objectProperty.getURI();
if (uri == null) {
return null;
}
return configFilesMap.get(uri);
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@ -241,10 +270,4 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
"ObjectPropertyDaoStub.getObjectPropertyList() not implemented.");
}
@Override
public String getCustomListViewConfigFileName(ObjectProperty objectProperty) {
throw new RuntimeException(
"ObjectPropertyDaoStub.getCustomListViewConfigFileName() not implemented.");
}
}

View file

@ -45,6 +45,7 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
private ObjectPropertyStatementDao objectPropertyStatementDao;
private OntologyDao ontologyDao;
private UserAccountsDao userAccountsDao;
private VClassDao vClassDao;
public void setDefaultNamespace(String defaultNamespace) {
this.defaultNamespace = defaultNamespace;
@ -81,6 +82,10 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
public void setUserAccountsDao(UserAccountsDao userAccountsDao) {
this.userAccountsDao = userAccountsDao;
}
public void setVClassDao(VClassDao vClassDao) {
this.vClassDao = vClassDao;
}
// ----------------------------------------------------------------------
// Stub methods
@ -130,6 +135,11 @@ return this.objectPropertyStatementDao; }
return this.userAccountsDao;
}
@Override
public VClassDao getVClassDao() {
return this.vClassDao;
}
// ----------------------------------------------------------------------
// Un-implemented methods
// ----------------------------------------------------------------------
@ -194,12 +204,6 @@ return this.objectPropertyStatementDao; }
"WebappDaoFactory.getDatatypeDao() not implemented.");
}
@Override
public VClassDao getVClassDao() {
throw new RuntimeException(
"WebappDaoFactory.getVClassDao() not implemented.");
}
@Override
public DataPropertyStatementDao getDataPropertyStatementDao() {
throw new RuntimeException(

View file

@ -0,0 +1,58 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.freemarker.cache;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
import freemarker.cache.TemplateLoader;
/**
* A simple implementation where the templates are stored a strings in a map
* instead of as files, and where the "template source" objects are just the
* template names.
*/
public class TemplateLoaderStub implements TemplateLoader {
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
private final Map<String, String> templateMap = new HashMap<String, String>();
public void createTemplate(String name, String contents) {
templateMap.put(name, contents);
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@Override
public Object findTemplateSource(String name) throws IOException {
if (templateMap.containsKey(name)) {
return name;
} else {
return null;
}
}
@Override
public void closeTemplateSource(Object templateSource) throws IOException {
// Nothing to close
}
@Override
public long getLastModified(Object templateSource) {
return -1;
}
@Override
public Reader getReader(Object templateSource, String encoding)
throws IOException {
return new StringReader(templateMap.get(templateSource));
}
}

View file

@ -3,6 +3,7 @@
package stubs.javax.servlet;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
@ -17,11 +18,14 @@ 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.
*/
@SuppressWarnings("deprecation")
public class ServletContextStub implements ServletContext {
private static final Log log = LogFactory.getLog(ServletContextStub.class);
// ----------------------------------------------------------------------
// Stub infrastructure
@ -37,7 +41,7 @@ public class ServletContextStub implements ServletContext {
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.");
@ -48,18 +52,32 @@ public class ServletContextStub implements ServletContext {
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).
* Use the prefix, a separator, and the filename as the path.
*/
public void setRealPaths(String pathPrefix, File dir) {
for (File file : dir.listFiles()) {
setRealPath(pathPrefix + File.separatorChar + file.getName(),
file.getPath());
}
}
// ----------------------------------------------------------------------
// Stub methods
// ----------------------------------------------------------------------
@ -104,7 +122,9 @@ public class ServletContextStub implements ServletContext {
@Override
public String getRealPath(String path) {
return realPaths.get(path);
String real = realPaths.get(path);
log.debug("Real path for '" + path + "' is '" + real + "'");
return real;
}
// ----------------------------------------------------------------------