Continue to reduce the Model Madness!
Add OntModelCache to the top of the stack of RDF data structures. Add DataStructuresProvider to the bottom of the stack. Redesign ModelAccess method signatures. Create the ShowSources page. Remove RequestModelsPrep, except for setting the Collator. Reduce the complexity of ContentModelsSetup and ConfigurationModelsSetup. VIVO-225 VIVO-819 VIVO-820 VIVO-821 VIVO-823 VIVO-832
This commit is contained in:
parent
c9362db3c1
commit
78c8f102f8
171 changed files with 4196 additions and 2826 deletions
|
@ -14,6 +14,7 @@ import org.junit.Test;
|
|||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
|
@ -29,7 +30,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.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?
|
||||
|
@ -80,7 +80,7 @@ public class HasPermissionFactoryTest extends AbstractTestClass {
|
|||
wdf.setUserAccountsDao(uaDao);
|
||||
|
||||
ctx = new ServletContextStub();
|
||||
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
|
||||
new ModelAccessFactoryStub().get(ctx).setWebappDaoFactory(wdf);
|
||||
|
||||
session = new HttpSessionStub();
|
||||
session.setServletContext(ctx);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.junit.Test;
|
|||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
|
@ -19,7 +20,6 @@ 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?
|
||||
|
@ -57,7 +57,7 @@ public class IsRootUserFactoryTest extends AbstractTestClass {
|
|||
wdf.setUserAccountsDao(uaDao);
|
||||
|
||||
ctx = new ServletContextStub();
|
||||
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
|
||||
new ModelAccessFactoryStub().get(ctx).setWebappDaoFactory(wdf);
|
||||
|
||||
session = new HttpSessionStub();
|
||||
session.setServletContext(ctx);
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.junit.Test;
|
|||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
|
@ -19,7 +20,6 @@ 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.
|
||||
|
@ -42,12 +42,12 @@ public class IsUserFactoryTest extends AbstractTestClass {
|
|||
@Before
|
||||
public void setup() {
|
||||
uaDao = new UserAccountsDaoStub();
|
||||
|
||||
|
||||
wdf = new WebappDaoFactoryStub();
|
||||
wdf.setUserAccountsDao(uaDao);
|
||||
|
||||
ctx = new ServletContextStub();
|
||||
ModelAccess.on(ctx).setWebappDaoFactory(wdf);
|
||||
new ModelAccessFactoryStub().get(ctx).setWebappDaoFactory(wdf);
|
||||
|
||||
session = new HttpSessionStub();
|
||||
session.setServletContext(ctx);
|
||||
|
@ -70,7 +70,7 @@ public class IsUserFactoryTest extends AbstractTestClass {
|
|||
LoginStatusBean lsb = new LoginStatusBean(USER_URI,
|
||||
AuthenticationSource.EXTERNAL);
|
||||
LoginStatusBean.setBean(session, lsb);
|
||||
|
||||
|
||||
UserAccount user = new UserAccount();
|
||||
user.setUri(USER_URI);
|
||||
uaDao.addUser(user);
|
||||
|
|
|
@ -27,6 +27,7 @@ import stubs.edu.cornell.mannlib.vitro.webapp.dao.IndividualDaoStub;
|
|||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.i18n.I18nStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.javax.servlet.ServletConfigStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
|
@ -48,7 +49,6 @@ 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;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -132,11 +132,15 @@ public class AuthenticateTest extends AbstractTestClass {
|
|||
authenticator.setAssociatedUri(OLD_SELF.username,
|
||||
"old_self_associated_uri");
|
||||
|
||||
servletContext = new ServletContextStub();
|
||||
servletContext.setAttribute(AuthenticatorStub.FACTORY_ATTRIBUTE_NAME,
|
||||
authenticatorFactory);
|
||||
|
||||
PermissionSet adminPermissionSet = new PermissionSet();
|
||||
adminPermissionSet.setUri(URI_DBA);
|
||||
adminPermissionSet.setPermissionUris(Collections
|
||||
.singleton(SimplePermission.SEE_SITE_ADMIN_PAGE.getUri()));
|
||||
|
||||
|
||||
userAccountsDao = new UserAccountsDaoStub();
|
||||
userAccountsDao.addPermissionSet(adminPermissionSet);
|
||||
userAccountsDao.addUser(createUserFromUserInfo(NEW_DBA));
|
||||
|
@ -150,10 +154,8 @@ public class AuthenticateTest extends AbstractTestClass {
|
|||
webappDaoFactory.setUserAccountsDao(userAccountsDao);
|
||||
webappDaoFactory.setIndividualDao(individualDao);
|
||||
|
||||
servletContext = new ServletContextStub();
|
||||
ModelAccess.on(servletContext).setWebappDaoFactory(webappDaoFactory);
|
||||
servletContext.setAttribute(AuthenticatorStub.FACTORY_ATTRIBUTE_NAME,
|
||||
authenticatorFactory);
|
||||
ModelAccessFactoryStub mafs = new ModelAccessFactoryStub();
|
||||
mafs.get(servletContext).setWebappDaoFactory(webappDaoFactory);
|
||||
|
||||
setLoggerLevel(ServletPolicyList.class, Level.WARN);
|
||||
ServletPolicyList.addPolicy(servletContext, new PermissionsPolicy());
|
||||
|
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.individual;
|
|||
import static com.hp.hpl.jena.ontology.OntModelSpec.OWL_MEM;
|
||||
import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.LABEL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.RDF_TYPE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption.LANGUAGE_NEUTRAL;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,6 +23,7 @@ import org.apache.log4j.Level;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
|
@ -45,8 +47,8 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
|
||||
|
@ -349,8 +351,7 @@ public class IndividualRdfAssemblerTest extends AbstractTestClass {
|
|||
|
||||
private void setupIndividualRdfAssembler() {
|
||||
rdfService = new RDFServiceModel(rawRdf);
|
||||
req.setAttribute("rdfService", rdfService);
|
||||
req.setAttribute("unfilteredRDFService", rdfService);
|
||||
new ModelAccessFactoryStub().get(req).setRDFService(rdfService, LANGUAGE_NEUTRAL);
|
||||
vreq = new VitroRequest(req);
|
||||
ira = new IndividualRdfAssembler(vreq, INDIVIDUAL_URI, ContentType.N3);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.junit.Test;
|
|||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modules.ApplicationStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineStub;
|
||||
import stubs.javax.servlet.ServletConfigStub;
|
||||
|
@ -29,7 +30,7 @@ import stubs.javax.servlet.http.HttpServletResponseStub;
|
|||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
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.modelaccess.ModelAccess;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
|
@ -107,7 +108,7 @@ public class JsonServletTest extends AbstractTestClass {
|
|||
resp = new HttpServletResponseStub();
|
||||
|
||||
wadf = new WebappDaoFactoryStub();
|
||||
ModelAccess.on(ctx).setWebappDaoFactory(wadf);
|
||||
new ModelAccessFactoryStub().get(req).setWebappDaoFactory(wadf);
|
||||
|
||||
vcDao = new VClassDaoStub();
|
||||
wadf.setVClassDao(vcDao);
|
||||
|
@ -185,9 +186,9 @@ public class JsonServletTest extends AbstractTestClass {
|
|||
|
||||
/**
|
||||
* TODO test successful responses. This will require figuring out how to
|
||||
* stub SearchEngine. Since we are no longer dealing with an abstract class
|
||||
* (like SolrServer), so we just need to figure out
|
||||
* what sort of NamedList is required as a response to a request.
|
||||
* stub SearchEngine. Since we are no longer dealing with an abstract class
|
||||
* (like SolrServer), so we just need to figure out what sort of NamedList
|
||||
* is required as a response to a request.
|
||||
*/
|
||||
@Test
|
||||
public void individualsByClassNoIndividuals() throws ServletException,
|
||||
|
@ -230,8 +231,10 @@ public class JsonServletTest extends AbstractTestClass {
|
|||
assertEquals("count", count, getFieldValue(actual, "totalCount"));
|
||||
|
||||
JSONObject vclassObj = (JSONObject) getFieldValue(actual, "vclass");
|
||||
assertEquals("vclass name", vclassId.split("://")[1], getFieldValue(vclassObj, "name"));
|
||||
assertEquals("vclass uri", vclassId, getFieldValue(vclassObj, "URI"));
|
||||
assertEquals("vclass name", vclassId.split("://")[1],
|
||||
getFieldValue(vclassObj, "name"));
|
||||
assertEquals("vclass uri", vclassId,
|
||||
getFieldValue(vclassObj, "URI"));
|
||||
|
||||
assertEquals("status", SC_OK, resp.getStatus());
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -28,7 +28,8 @@ import com.hp.hpl.jena.shared.DoesNotExistException;
|
|||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Test the functions of a ListCachingModelMaker. Does it properly register the
|
||||
* presence of a model with no triples?
|
||||
*/
|
||||
public class ListCachingModelMakerTest extends AbstractTestClass {
|
||||
private static final String URI_ONE = "http://model.one";
|
||||
|
|
|
@ -31,7 +31,8 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
|||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Checks the function of a MemoryMappingModelMaker, testing the difference in
|
||||
* behavior between an mapped model and an unmapped model.
|
||||
*/
|
||||
public class MemoryMappingModelMakerTest extends AbstractTestClass {
|
||||
private static final String URI_MAPPED = "http://memory.mapped.model";
|
||||
|
|
|
@ -1,259 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.modelaccess.adapters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.com.hp.hpl.jena.rdf.model.ModelMaker.ModelMakerStub;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
import com.hp.hpl.jena.shared.AlreadyExistsException;
|
||||
import com.hp.hpl.jena.shared.CannotCreateException;
|
||||
import com.hp.hpl.jena.shared.DoesNotExistException;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.UnionModelsModelMaker.UnionSpec;
|
||||
|
||||
/**
|
||||
* Test the functionality of the UnionModelsModelMaker.
|
||||
*/
|
||||
public class UnionModelsModelMakerTest extends AbstractTestClass {
|
||||
private static final String URI_ONE = "http://model.one";
|
||||
private static final String URI_TWO = "http://model.two";
|
||||
private static final String URI_THREE = "http://model.three";
|
||||
private static final String URI_UNION = "http://model.union";
|
||||
private static final String URI_NONE = "http://model.does.not.exist";
|
||||
|
||||
private static final Model MODEL_ONE = createModel();
|
||||
private static final Model MODEL_TWO = createModel();
|
||||
private static final Model MODEL_THREE = createModel();
|
||||
private static final Model MODEL_DEFAULT = createModel();
|
||||
private static final Model MODEL_FRESH = createModel();
|
||||
|
||||
private static Model createModel() {
|
||||
return ModelFactory.createDefaultModel();
|
||||
}
|
||||
|
||||
private ModelMaker inner;
|
||||
private ModelMaker mm;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
/*
|
||||
* Use a rigorous inner model maker, but it doesn't make much difference.
|
||||
*/
|
||||
inner = ModelMakerStub.rigorous(MODEL_DEFAULT, MODEL_FRESH)
|
||||
.put(URI_ONE, MODEL_ONE).put(URI_TWO, MODEL_TWO)
|
||||
.put(URI_THREE, MODEL_THREE);
|
||||
|
||||
mm = new UnionModelsModelMaker(inner, UnionSpec.base(URI_ONE)
|
||||
.plus(URI_TWO).yields(URI_UNION));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void nullInnerModel() {
|
||||
new UnionModelsModelMaker(null, UnionSpec.base(URI_ONE).plus(URI_TWO)
|
||||
.yields(URI_UNION));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void duplicateUnionUri() {
|
||||
new UnionModelsModelMaker(inner, UnionSpec.base(URI_ONE).plus(URI_TWO)
|
||||
.yields(URI_UNION), UnionSpec.base(URI_ONE).plus(URI_THREE)
|
||||
.yields(URI_UNION));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nestedUnions() {
|
||||
new UnionModelsModelMaker(inner, UnionSpec.base(URI_ONE).plus(URI_TWO)
|
||||
.yields(URI_UNION), UnionSpec.base(URI_UNION).plus(URI_THREE)
|
||||
.yields("http://nestedUnion"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasModelActual() {
|
||||
assertTrue(mm.hasModel(URI_ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasModelNone() {
|
||||
assertFalse(mm.hasModel(URI_NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasModelUnion() {
|
||||
assertTrue(mm.hasModel(URI_UNION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listModels() {
|
||||
assertExpectedModelsList(URI_ONE, URI_TWO, URI_THREE, URI_UNION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModelActual() {
|
||||
assertEquals(MODEL_ONE, mm.createModel(URI_ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModelNone() {
|
||||
assertEquals(MODEL_FRESH, mm.createModel(URI_NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModelUnion() {
|
||||
assertTrue(isUnionModel(mm.createModel(URI_UNION)));
|
||||
}
|
||||
|
||||
@Test(expected = AlreadyExistsException.class)
|
||||
public void createModelActualStrict() {
|
||||
mm.createModel(URI_ONE, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModelNoneStrict() {
|
||||
assertEquals(MODEL_FRESH, mm.createModel(URI_NONE, true));
|
||||
}
|
||||
|
||||
@Test(expected = AlreadyExistsException.class)
|
||||
public void createModelUnionStrict() {
|
||||
mm.createModel(URI_UNION, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelActual() {
|
||||
assertEquals(MODEL_ONE, mm.openModel(URI_ONE));
|
||||
}
|
||||
|
||||
@Test(expected = DoesNotExistException.class)
|
||||
public void openModelNone() {
|
||||
mm.openModel(URI_NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelUnion() {
|
||||
assertTrue(isUnionModel(mm.openModel(URI_UNION)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelActualStrict() {
|
||||
assertEquals(MODEL_ONE, mm.openModel(URI_ONE, true));
|
||||
}
|
||||
|
||||
@Test(expected = DoesNotExistException.class)
|
||||
public void openModelNoneStrict() {
|
||||
mm.openModel(URI_NONE, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelUnionStrict() {
|
||||
assertTrue(isUnionModel(mm.openModel(URI_UNION, true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelIfPresentActual() {
|
||||
assertEquals(MODEL_ONE, mm.openModelIfPresent(URI_ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelIfPresentNone() {
|
||||
assertNull(mm.openModelIfPresent(URI_NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openModelIfPresentUnion() {
|
||||
assertTrue(isUnionModel(mm.openModelIfPresent(URI_UNION)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeModelActual() {
|
||||
mm.removeModel(URI_ONE);
|
||||
assertExpectedModelsList(URI_TWO, URI_THREE, URI_UNION);
|
||||
}
|
||||
|
||||
@Test(expected = DoesNotExistException.class)
|
||||
public void removeModelNone() {
|
||||
mm.removeModel(URI_NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeModelUnion() {
|
||||
mm.removeModel(URI_UNION);
|
||||
assertExpectedModelsList(URI_ONE, URI_TWO, URI_THREE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModelActual() {
|
||||
assertEquals(MODEL_ONE, mm.getModel(URI_ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModelNone() {
|
||||
assertEquals(null, mm.getModel(URI_NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModelUnion() {
|
||||
assertTrue(isUnionModel(mm.getModel(URI_UNION)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModelLoadIfAbsentActual() {
|
||||
assertEquals(MODEL_ONE, mm.getModel(URI_ONE, null));
|
||||
}
|
||||
|
||||
@Test(expected = CannotCreateException.class)
|
||||
public void getModelLoadIfAbsentNone() {
|
||||
mm.getModel(URI_NONE, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getModelLoadIfAbsentUnion() {
|
||||
assertTrue(isUnionModel(mm.getModel(URI_UNION, null)));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* No easy way to assert that this is actually the union model, but we can
|
||||
* assert that it is not null, and not any model we know of.
|
||||
*/
|
||||
private boolean isUnionModel(Model m) {
|
||||
Model[] knownModels = { MODEL_ONE, MODEL_TWO, MODEL_THREE,
|
||||
MODEL_DEFAULT, MODEL_FRESH };
|
||||
if (m == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Model knownModel : knownModels) {
|
||||
if (m == knownModel) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void assertExpectedModelsList(String... uris) {
|
||||
Set<String> expected = new HashSet<>(Arrays.asList(uris));
|
||||
assertEquals(expected, mm.listModels().toSet());
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption.ASSERTIONS_AND_INFERENCES;
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.FULL_UNION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -27,6 +29,7 @@ import org.junit.rules.ExpectedException;
|
|||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccessFactoryStub;
|
||||
import stubs.freemarker.cache.TemplateLoaderStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
|
@ -41,9 +44,7 @@ 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.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
@ -70,6 +71,8 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
private TemplateLoaderStub tl;
|
||||
|
||||
private StringWriter logMessages;
|
||||
|
||||
private ModelAccessFactoryStub mafs;
|
||||
|
||||
/**
|
||||
* In general, we expect no exception, but individual tests may override,
|
||||
|
@ -130,7 +133,9 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
hreq.setSession(session);
|
||||
|
||||
vreq = new VitroRequest(hreq);
|
||||
ModelAccess.on(vreq).setWebappDaoFactory(wadf);
|
||||
|
||||
mafs = new ModelAccessFactoryStub();
|
||||
mafs.get(vreq).setWebappDaoFactory(wadf, ASSERTIONS_AND_INFERENCES);
|
||||
|
||||
subject = new IndividualImpl();
|
||||
|
||||
|
@ -280,7 +285,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
@Test
|
||||
public void constructQueryNodeMissing()
|
||||
throws InvalidConfigurationException {
|
||||
ModelAccess.on(vreq).setOntModel(ModelNames.FULL_UNION, emptyOntModel());
|
||||
mafs.get(vreq).setOntModel(emptyOntModel(), FULL_UNION);
|
||||
op = buildOperation("constructQueryMissing");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, true);
|
||||
// Not an error.
|
||||
|
@ -289,7 +294,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
@Test
|
||||
public void constructQueryMultipleValues()
|
||||
throws InvalidConfigurationException {
|
||||
ModelAccess.on(vreq).setOntModel(ModelNames.FULL_UNION, emptyOntModel());
|
||||
mafs.get(vreq).setOntModel(emptyOntModel(), FULL_UNION);
|
||||
op = buildOperation("constructQueryMultiple");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, true);
|
||||
assertConstructQueries("multiple construct queries", "ONE", "TWO",
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption.ASSERTIONS_AND_INFERENCES;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
|
||||
/**
|
||||
* A mock instance of ContextModelAccess for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class ContextModelAccessStub implements ContextModelAccess {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<ReasoningOption, WebappDaoFactory> wadfMap = new HashMap<>();
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf) {
|
||||
setWebappDaoFactory(wadf, ASSERTIONS_AND_INFERENCES);
|
||||
}
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf,
|
||||
ReasoningOption option) {
|
||||
wadfMap.put(option, wadf);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory() {
|
||||
return wadfMap.get(ASSERTIONS_AND_INFERENCES);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getRDFService() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getRDFService() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset getDataset() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset getDataset(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelMaker getModelMaker() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getModelMaker() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelMaker getModelMaker(WhichService which) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getModelMaker() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModel() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(String name) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModel() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector() {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector(ReasoningOption option) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory(ReasoningOption option) {
|
||||
throw new RuntimeException(
|
||||
"ContextModelAccessStub.getWebappDaoFactory() not implemented.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ModelAccessFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.RequestModelAccess;
|
||||
|
||||
/**
|
||||
* A mock instance of ModelAccessFactory for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class ModelAccessFactoryStub extends ModelAccessFactory {
|
||||
private final ContextModelAccessStub contextMA;
|
||||
private final RequestModelAccessStub requestMA;
|
||||
|
||||
public ModelAccessFactoryStub() {
|
||||
try {
|
||||
Field factoryField = ModelAccess.class.getDeclaredField("factory");
|
||||
factoryField.setAccessible(true);
|
||||
factoryField.set(null, this);
|
||||
} catch (NoSuchFieldException | SecurityException
|
||||
| IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new RuntimeException(
|
||||
"Failed to create the ModelAccessFactoryStub", e);
|
||||
}
|
||||
|
||||
contextMA = new ContextModelAccessStub();
|
||||
requestMA = new RequestModelAccessStub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextModelAccess buildContextModelAccess(ServletContext ctx) {
|
||||
return contextMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestModelAccess buildRequestModelAccess(HttpServletRequest req) {
|
||||
return requestMA;
|
||||
}
|
||||
|
||||
public ContextModelAccessStub get(ServletContext ctx) {
|
||||
return contextMA;
|
||||
}
|
||||
|
||||
public RequestModelAccessStub get(HttpServletRequest req) {
|
||||
return requestMA;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.edu.cornell.mannlib.vitro.webapp.modelaccess;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.DatasetOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.LanguageOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.OntModelSelectorOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.RdfServiceOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WebappDaoFactoryOption;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.RequestModelAccess;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.OntModelKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.RDFServiceKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.WebappDaoFactoryKey;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||
|
||||
/**
|
||||
* A mock instance of RequestModelAccess for use in unit tests.
|
||||
*
|
||||
* I have only implemented the methods that I needed for my tests. Feel free to
|
||||
* implement the rest, as needed.
|
||||
*/
|
||||
public class RequestModelAccessStub implements RequestModelAccess {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<RDFServiceKey, RDFService> rdfServiceMap = new HashMap<>();
|
||||
|
||||
public void setRDFService(RDFService rdfService,
|
||||
RdfServiceOption... options) {
|
||||
rdfServiceMap.put(new RDFServiceKey(options), rdfService);
|
||||
}
|
||||
|
||||
private final Map<OntModelKey, OntModel> ontModelMap = new HashMap<>();
|
||||
|
||||
public void setOntModel(OntModel model, String name) {
|
||||
ontModelMap.put(new OntModelKey(name), model);
|
||||
}
|
||||
|
||||
private final Map<WebappDaoFactoryKey, WebappDaoFactory> wadfMap = new HashMap<>();
|
||||
|
||||
public void setWebappDaoFactory(WebappDaoFactory wadf,
|
||||
WebappDaoFactoryOption... options) {
|
||||
wadfMap.put(new WebappDaoFactoryKey(options), wadf);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public RDFService getRDFService(RdfServiceOption... options) {
|
||||
return rdfServiceMap.get(new RDFServiceKey(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(LanguageOption... options) {
|
||||
return getOntModel(ModelNames.FULL_UNION, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModel getOntModel(String name, LanguageOption... options) {
|
||||
return ontModelMap.get(new OntModelKey(name, options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory(
|
||||
WebappDaoFactoryOption... options) {
|
||||
return wadfMap.get(new WebappDaoFactoryKey(options));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Dataset getDataset(DatasetOption... options) {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.getDataset() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OntModelSelector getOntModelSelector(
|
||||
OntModelSelectorOption... options) {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.getOntModelSelector() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
throw new RuntimeException(
|
||||
"RequestModelAccessStub.close() not implemented.");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue