VIVO-82 Use ModelAccess to store and get WebappDaoFactory references.

This commit is contained in:
j2blake 2013-05-21 17:45:48 -04:00
parent c086a595e1
commit 4928940849
35 changed files with 166 additions and 237 deletions

View file

@ -29,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/**
* Can we tell whether a user is logged in as root?
@ -79,7 +80,7 @@ public class HasPermissionFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf);
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub();
session.setServletContext(ctx);

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsRootUser;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/**
* Can we tell whether a user is logged in as root?
@ -56,7 +57,7 @@ public class IsRootUserFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf);
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub();
session.setServletContext(ctx);

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsUser;
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/**
* The simplest of the IdentifierBundleFactory classes.
@ -46,7 +47,7 @@ public class IsUserFactoryTest extends AbstractTestClass {
wdf.setUserAccountsDao(uaDao);
ctx = new ServletContextStub();
ctx.setAttribute("webappDaoFactory", wdf);
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
session = new HttpSessionStub();
session.setServletContext(ctx);

View file

@ -47,6 +47,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.AuthenticatorStub;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
/**
*/
@ -147,7 +148,7 @@ public class AuthenticateTest extends AbstractTestClass {
webappDaoFactory.setIndividualDao(individualDao);
servletContext = new ServletContextStub();
servletContext.setAttribute("webappDaoFactory", webappDaoFactory);
ModelAccess.on(servletContext).setWebappDaoFactory(webappDaoFactory);
servletContext.setAttribute(AuthenticatorStub.FACTORY_ATTRIBUTE_NAME,
authenticatorFactory);

View file

@ -28,6 +28,7 @@ import stubs.javax.servlet.http.HttpSessionStub;
import stubs.org.apache.solr.client.solrj.SolrServerStub;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
/**
@ -106,8 +107,7 @@ public class JsonServletTest extends AbstractTestClass {
resp = new HttpServletResponseStub();
wadf = new WebappDaoFactoryStub();
req.setAttribute("webappDaoFactory", wadf);
ctx.setAttribute("webappDaoFactory", wadf);
ModelAccess.on(ctx).setWebappDaoFactory(wadf);
vcDao = new VClassDaoStub();
wadf.setVClassDao(vcDao);

View file

@ -18,6 +18,7 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
@ -48,7 +49,7 @@ public class PageDataGetterUtilsTest extends AbstractTestClass{
@Test
public void testGetPageDataGetterObjects() throws Exception{
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
vreq.setWebappDaoFactory(wdf);
ModelAccess.on(vreq).setWebappDaoFactory(wdf);
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI);
Assert.assertNotNull(pdgList);
@ -58,7 +59,7 @@ public class PageDataGetterUtilsTest extends AbstractTestClass{
@Test
public void testGetNonPageDataGetterObjects() throws Exception{
VitroRequest vreq = new VitroRequest( new HttpServletRequestStub() );
vreq.setWebappDaoFactory(wdf);
ModelAccess.on(vreq).setWebappDaoFactory(wdf);
List<PageDataGetter> pdgList = PageDataGetterUtils.getPageDataGetterObjects(vreq, pageURI_2);
Assert.assertNotNull(pdgList);

View file

@ -25,6 +25,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
import stubs.freemarker.cache.TemplateLoaderStub;
@ -36,6 +40,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
@ -123,7 +129,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
hreq.setSession(session);
vreq = new VitroRequest(hreq);
vreq.setWebappDaoFactory(wadf);
ModelAccess.on(vreq).setWebappDaoFactory(wadf);
subject = new IndividualImpl();
@ -273,6 +279,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void constructQueryNodeMissing()
throws InvalidConfigurationException {
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, emptyOntModel());
op = buildOperation("constructQueryMissing");
optm = new NonCollatingOPTM(op, subject, vreq, true);
// Not an error.
@ -281,6 +288,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
@Test
public void constructQueryMultipleValues()
throws InvalidConfigurationException {
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, emptyOntModel());
op = buildOperation("constructQueryMultiple");
optm = new NonCollatingOPTM(op, subject, vreq, true);
assertConstructQueries("multiple construct queries", "ONE", "TWO",
@ -367,6 +375,10 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
// Helper methods
// ----------------------------------------------------------------------
private OntModel emptyOntModel() {
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
}
/**
* Sets up an operation with name "foobar" and adds it to the
* ObjectPropertyDaoStub.

View file

@ -12,10 +12,11 @@ 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.
*/
@SuppressWarnings("deprecation")
public class HttpSessionStub implements HttpSession {
private static final Log log = LogFactory.getLog(HttpSessionStub.class);
@ -49,7 +50,11 @@ public class HttpSessionStub implements HttpSession {
@Override
public ServletContext getServletContext() {
return this.context;
if (this.context == null) {
return new ServletContextStub();
} else {
return this.context;
}
}
@Override
@ -149,6 +154,7 @@ public class HttpSessionStub implements HttpSession {
"HttpSessionStub.putValue() not implemented.");
}
@Override
public void removeValue(String arg0) {
throw new RuntimeException(
"HttpSessionStub.removeValue() not implemented.");