Merge branch 'develop' of github.com:vivo-project/Vitro into develop

This commit is contained in:
Brian Caruso 2013-07-08 13:52:05 -04:00
commit 467256e3ba
406 changed files with 8250 additions and 4587 deletions

View file

@ -0,0 +1,431 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vedit.util;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
/**
* All of these tests are for OperationUtils.cloneBean()
*/
public class OperationUtils_CloneBeanTest extends AbstractTestClass {
// ----------------------------------------------------------------------
// Allow the tests to expect a RuntimeException with a particular cause.
// ----------------------------------------------------------------------
@Rule
public ExpectedException thrown = ExpectedException.none();
Matcher<?> causedBy(Class<? extends Throwable> causeClass) {
return new CausedByMatcher(causeClass);
}
class CausedByMatcher extends BaseMatcher<Throwable> {
private final Class<? extends Throwable> causeClass;
public CausedByMatcher(Class<? extends Throwable> causeClass) {
this.causeClass = causeClass;
}
@Override
public boolean matches(Object actualThrowable) {
if (!(actualThrowable instanceof RuntimeException)) {
return false;
}
Throwable cause = ((RuntimeException) actualThrowable).getCause();
return causeClass.isInstance(cause);
}
@Override
public void describeTo(Description d) {
d.appendText("RuntimeException caused by " + causeClass.getName());
}
}
// ----------------------------------------------------------------------
// Test for invalid classes
// ----------------------------------------------------------------------
@Test(expected = NullPointerException.class)
public void nullArgument() {
OperationUtils.cloneBean(null);
}
@Test(expected = NullPointerException.class)
public void nullBean() {
OperationUtils
.cloneBean(null, SimpleSuccess.class, SimpleSuccess.class);
}
@Test(expected = NullPointerException.class)
public void nullBeanClass() {
OperationUtils
.cloneBean(new SimpleSuccess(), null, SimpleSuccess.class);
}
@Test(expected = NullPointerException.class)
public void nullInterfaceClass() {
OperationUtils
.cloneBean(new SimpleSuccess(), SimpleSuccess.class, null);
}
@Test(expected = IllegalAccessException.class)
@Ignore("Why doesn't this throw an exception?")
public void privateClass() {
OperationUtils.cloneBean(new PrivateClass());
}
@Test
public void privateConstructor() {
thrown.expect(causedBy(NoSuchMethodException.class));
OperationUtils.cloneBean(new PrivateConstructor());
}
@Test
public void abstractClass() {
thrown.expect(causedBy(InstantiationException.class));
OperationUtils.cloneBean(new ConcreteOfAbstractClass(),
AbstractClass.class, AbstractClass.class);
}
@Test
public void interfaceClass() {
thrown.expect(causedBy(InstantiationException.class));
OperationUtils.cloneBean(new ConcreteOfInterfaceClass(),
InterfaceClass.class, InterfaceClass.class);
}
@Test
public void arrayClass() {
thrown.expect(causedBy(NoSuchMethodException.class));
OperationUtils.cloneBean(new String[0]);
}
@Test
public void primitiveTypeClass() {
thrown.expect(causedBy(NoSuchMethodException.class));
OperationUtils.cloneBean(1, Integer.TYPE, Integer.TYPE);
}
@Test
public void voidClass() {
thrown.expect(causedBy(NoSuchMethodException.class));
OperationUtils.cloneBean(new Object(), Void.TYPE, Void.TYPE);
}
@Test
public void noNullaryConstructor() {
thrown.expect(causedBy(NoSuchMethodException.class));
OperationUtils.cloneBean(new NoNullaryConstructor(1));
}
@Test(expected = ExceptionInInitializerError.class)
public void classThrowsExceptionWhenLoaded() {
OperationUtils.cloneBean(new ThrowsExceptionWhenLoaded());
}
@Test
public void initializerThrowsException() {
thrown.expect(causedBy(InvocationTargetException.class));
OperationUtils.cloneBean("random object",
InitializerThrowsException.class,
InitializerThrowsException.class);
}
@Test
public void wrongInterfaceClass() {
thrown.expect(causedBy(IllegalArgumentException.class));
OperationUtils.cloneBean(new WrongConcreteClass(),
WrongConcreteClass.class, WrongInterface.class);
}
@Test
public void getThrowsException() {
thrown.expect(causedBy(InvocationTargetException.class));
OperationUtils.cloneBean(new GetMethodThrowsException());
}
@Test
public void setThrowsException() {
thrown.expect(causedBy(InvocationTargetException.class));
OperationUtils.cloneBean(new SetMethodThrowsException());
}
private static class PrivateClass {
public PrivateClass() {
}
}
private static class PrivateConstructor {
private PrivateConstructor() {
}
}
public abstract static class AbstractClass {
public AbstractClass() {
}
}
public static class ConcreteOfAbstractClass extends AbstractClass {
public ConcreteOfAbstractClass() {
}
}
public abstract static class InterfaceClass {
public InterfaceClass() {
}
}
public static class ConcreteOfInterfaceClass extends InterfaceClass {
public ConcreteOfInterfaceClass() {
}
}
public static class NoNullaryConstructor {
@SuppressWarnings("unused")
public NoNullaryConstructor(int i) {
// nothing to do
}
}
public static class ThrowsExceptionWhenLoaded {
static {
if (true)
throw new IllegalArgumentException();
}
}
public static class InitializerThrowsException {
{
if (true)
throw new IllegalStateException("Initializer throws exception");
}
}
public static class WrongConcreteClass {
private String junk = "junk";
public String getJunk() {
return this.junk;
}
@SuppressWarnings("unused")
private void setJunk(String junk) {
this.junk = junk;
}
}
public static interface WrongInterface {
String getJunk();
void setJunk(String junk);
}
public static class GetMethodThrowsException {
@SuppressWarnings("unused")
private String junk = "junk";
public String getJunk() {
throw new UnsupportedOperationException();
}
public void setJunk(String junk) {
this.junk = junk;
}
}
public static class SetMethodThrowsException {
private String junk = "junk";
public String getJunk() {
return this.junk;
}
@SuppressWarnings("unused")
public void setJunk(String junk) {
throw new UnsupportedOperationException();
}
}
// ----------------------------------------------------------------------
// Test simple success and innocuous variations
// ----------------------------------------------------------------------
@Test
public void simpleSuccess() {
expectSuccess(new SimpleSuccess().insertField("label", "a prize"));
}
@Test
public void getButNoSet() {
expectSuccess(new GetButNoSet().insertField("label", "shouldBeEqual"));
}
@Test
public void getTakesParameters() {
expectSuccess(new GetTakesParameters().insertField("label", "fine"));
}
@Test
public void getReturnsVoid() {
expectSuccess(new GetReturnsVoid().insertField("label", "fine"));
}
@Test
public void getAndSetDontMatch() {
expectSuccess(new GetAndSetDontMatch().insertField("label", "fine"));
}
@Test
public void getIsStatic() {
expectSuccess(new GetIsStatic().insertField("label", "fine")
.insertField("instanceJunk", "the junk"));
}
@Test
public void getMethodIsPrivate() {
expectSuccess(new GetMethodIsPrivate().insertField("label", "fine"));
}
@Test
public void setMethodIsPrivate() {
expectSuccess(new SetMethodIsPrivate().insertField("label", "fine"));
}
private void expectSuccess(BeanBase original) {
BeanBase cloned = (BeanBase) OperationUtils.cloneBean(original);
assertEquals("Simple success", original, cloned);
}
public static abstract class BeanBase {
protected final Map<String, Object> fields = new HashMap<>();
public BeanBase insertField(String key, Object value) {
if (value != null) {
fields.put(key, value);
}
return this;
}
@Override
public int hashCode() {
return fields.hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o == null) {
return false;
}
if (!this.getClass().equals(o.getClass())) {
return false;
}
return this.fields.equals(((BeanBase) o).fields);
}
@Override
public String toString() {
return this.getClass().getSimpleName() + fields;
}
}
public static class SimpleSuccess extends BeanBase {
public String getLabel() {
return (String) fields.get("label");
}
public void setLabel(String label) {
insertField("label", label);
}
}
public static class GetButNoSet extends SimpleSuccess {
public String getJunk() {
throw new UnsupportedOperationException();
}
}
public static class GetTakesParameters extends SimpleSuccess {
@SuppressWarnings("unused")
public String getJunk(String why) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("unused")
public void setJunk(String junk) {
throw new UnsupportedOperationException();
}
}
public static class GetReturnsVoid extends SimpleSuccess {
public void getJunk() {
throw new UnsupportedOperationException();
}
@SuppressWarnings("unused")
public void setJunk(String junk) {
throw new UnsupportedOperationException();
}
}
public static class GetAndSetDontMatch extends SimpleSuccess {
public String getJunk() {
throw new UnsupportedOperationException();
}
@SuppressWarnings("unused")
public void setJunk(Integer junk) {
throw new UnsupportedOperationException();
}
}
public static class GetIsStatic extends SimpleSuccess {
public static String getJunk() {
return ("the junk");
}
public void setJunk(String junk) {
insertField("instanceJunk", junk);
}
}
public static class GetMethodIsPrivate extends SimpleSuccess {
@SuppressWarnings("unused")
private String getJunk() {
return ("the junk");
}
public void setJunk(String junk) {
insertField("instanceJunk", junk);
}
}
public static class SetMethodIsPrivate extends SimpleSuccess {
public String getJunk() {
return ("the junk");
}
@SuppressWarnings("unused")
private void setJunk(String junk) {
insertField("instanceJunk", junk);
}
}
}

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

@ -73,7 +73,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
bean = new PropertyRestrictionPolicyHelper(
Arrays.asList(PROHIBITED_NAMESPACES),
Arrays.asList(PERMITTED_EXCEPTIONS), displayLevels,
modifyLevels);
modifyLevels, ModelFactory.createDefaultModel());
}
@Before

View file

@ -26,6 +26,7 @@ import stubs.edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesStub
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.javax.servlet.ServletConfigStub;
import stubs.javax.servlet.ServletContextStub;
import stubs.javax.servlet.http.HttpServletRequestStub;
@ -47,6 +48,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;
/**
*/
@ -119,6 +121,11 @@ public class AuthenticateTest extends AbstractTestClass {
@Before
public void setup() throws Exception {
// Create an I18n module that has a value for any key, but the value is
// the key itself.
@SuppressWarnings("unused")
I18nStub i18n = new I18nStub();
authenticatorFactory = new AuthenticatorStub.Factory();
authenticator = authenticatorFactory.getInstance(request);
authenticator.addUser(createUserFromUserInfo(NEW_DBA));
@ -147,7 +154,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);
@ -313,7 +320,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(LOGGING_IN, NO_USER, NO_MSG,
"Please enter your email address.", URL_LOGIN, URL_WITH_LINK);
"error_no_email_address", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -325,8 +332,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(LOGGING_IN, "unknownBozo", NO_MSG,
"The email or password you entered is incorrect.", URL_LOGIN,
URL_WITH_LINK);
"error_incorrect_credentials", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -338,7 +344,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(LOGGING_IN, NEW_DBA_NAME, NO_MSG,
"Please enter your password.", URL_LOGIN, URL_WITH_LINK);
"error_no_password", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -350,8 +356,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(LOGGING_IN, NEW_DBA_NAME, NO_MSG,
"The email or password you entered is incorrect.", URL_LOGIN,
URL_WITH_LINK);
"error_incorrect_credentials", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -402,8 +407,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG,
"Please enter a password between 6 and 12 "
+ "characters in length.", URL_LOGIN, URL_WITH_LINK);
"error_password_length", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -416,7 +420,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG,
"The passwords entered do not match.", URL_LOGIN, URL_WITH_LINK);
"error_passwords_dont_match", URL_LOGIN, URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}
@ -429,7 +433,7 @@ public class AuthenticateTest extends AbstractTestClass {
doTheRequest();
assertProcessBean(FORCED_PASSWORD_CHANGE, NEW_DBA_NAME, NO_MSG,
"Your new password cannot match the current one.", URL_LOGIN,
"error_previous_password", URL_LOGIN,
URL_WITH_LINK);
assertRedirectToLoginProcessPage();
}

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

@ -8,6 +8,9 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
@ -57,7 +60,7 @@ public class PropertyRestrictionPolicyHelperStub extends
Map<String, RoleLevel> displayThresholds,
Map<String, RoleLevel> modifyThresholds) {
super(modifyRestrictedNamespaces, modifyPermittedExceptions,
displayThresholds, modifyThresholds);
displayThresholds, modifyThresholds, ModelFactory.createDefaultModel());
}
}

View file

@ -65,6 +65,11 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
}
return opMap.get(objectPropertyURI);
}
@Override
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI) {
return getObjectPropertyByURI(objectPropertyURI);
}
@Override
public String getCustomListViewConfigFileName(ObjectProperty objectProperty) {

View file

@ -216,7 +216,7 @@ public class ObjectPropertyStatementDaoStub implements
@Override
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String propertyUri, String objectKey,
String subjectUri, String propertyUri, String objectKey, String rangeUri,
String query, Set<String> constructQueries, String sortDir) {
throw new RuntimeException(
"ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented.");

View file

@ -0,0 +1,78 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package stubs.edu.cornell.mannlib.vitro.webapp.i18n;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Enumeration;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
/**
* An implementation of I18n for unit tests. Construct a new instance and it
* replaces the instance of I18n.
*
* Each bundle that you get from it is the same, returning the key itself as the
* value of that key.
*/
public class I18nStub extends I18n {
private static final Log log = LogFactory.getLog(I18nStub.class);
// ----------------------------------------------------------------------
// Stub infrastructure
// ----------------------------------------------------------------------
public I18nStub() {
try {
Field instanceField = I18n.class.getDeclaredField("instance");
log.debug("Field is " + instanceField);
instanceField.setAccessible(true);
log.debug("Instance is " + instanceField.get(null));
instanceField.set(null, this);
log.debug("Instance is " + instanceField.get(null));
log.debug("Created and inserted.");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
protected I18nBundle getBundle(String bundleName, HttpServletRequest req) {
return new I18nBundleStub(bundleName);
}
private class I18nBundleStub extends I18nBundle {
public I18nBundleStub(String bundleName) {
super(bundleName, new DummyResourceBundle());
}
@Override
public String text(String key, Object... parameters) {
return key;
}
}
/**
* Not actually used, but the constructor of I18nBundle requires a non-null
* ResourceBundle.
*/
private class DummyResourceBundle extends ResourceBundle {
@Override
protected Object handleGetObject(String key) {
return key;
}
@Override
public Enumeration<String> getKeys() {
return Collections.emptyEnumeration();
}
}
}

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.");