Remove an unused filter, and several unused or empty unit test classes, with data files.
This commit is contained in:
parent
fbf484b537
commit
cf13f22f36
9 changed files with 0 additions and 2223 deletions
|
@ -1,278 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ResourceBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public class HiddenFromDisplayBelowRoleLevelFilter extends VitroFiltersImpl {
|
||||
|
||||
protected final RoleLevel userRole;
|
||||
protected final WebappDaoFactory wdf;
|
||||
|
||||
/* looking up data properties was taking %11 of search index build time
|
||||
* So this is a cache of DataProperty objects for this filter */
|
||||
protected final Map<String,DataProperty> dataPropertyMap;
|
||||
|
||||
/* Controls if whether to filter out individuals if the classes that
|
||||
* the individual belongs to are not visible. This has been
|
||||
* a minor performance problem. */
|
||||
protected final static boolean FILTER_ON_INDIVIDUAL_VCLASSES = false;
|
||||
|
||||
private final static Log log = LogFactory.getLog(HiddenFromDisplayBelowRoleLevelFilter.class);
|
||||
|
||||
public HiddenFromDisplayBelowRoleLevelFilter( RoleLevel role , WebappDaoFactory wdf ){
|
||||
super();
|
||||
if( role == null ) {
|
||||
throw new IllegalArgumentException("HiddenFromRoleLevelFilter must have a RoleLevel ");
|
||||
} else {
|
||||
log.debug("initializing HiddenFromDisplayBelowRoleLevelFilter with role "+role.getShorthand());
|
||||
}
|
||||
if( wdf == null )
|
||||
throw new IllegalArgumentException("HiddenFromRoleLevelFilter must have a DaoFactory");
|
||||
this.userRole = role;
|
||||
this.wdf = wdf;
|
||||
this.dataPropertyMap = new TreeMap<String,DataProperty>();
|
||||
|
||||
setIndividualFilter(new IndividualRoleFilter() );
|
||||
setClassFilter(new RoleFilter<VClass>());
|
||||
setDataPropertyFilter(new RoleFilter<DataProperty>() );
|
||||
setObjectPropertyFilter(new RoleFilter<ObjectProperty>() );
|
||||
setDataPropertyStatementFilter(new DataPropertyStatementRoleFilter<DataPropertyStatement>( ) );
|
||||
setObjectPropertyStatementFilter(new ObjectPropertyStatementRoleFilter<ObjectPropertyStatement>() );
|
||||
}
|
||||
|
||||
private boolean sameLevelOrHigher( RoleLevel other ){
|
||||
if( other == null )
|
||||
return true; //default to visible
|
||||
int comparison = userRole.compareTo(other);
|
||||
if (log.isDebugEnabled()) {
|
||||
if (comparison == 0) {
|
||||
log.debug("user role "+userRole.getShorthand()+" judged equal to current user role "+other.getShorthand());
|
||||
} else if (comparison > 0) {
|
||||
log.debug("user role "+userRole.getShorthand()+" judged greater than current user role "+other.getShorthand());
|
||||
} else if (comparison < 0) {
|
||||
log.debug("user role "+userRole.getShorthand()+" judged less than current user role "+other.getShorthand());
|
||||
}
|
||||
}
|
||||
return ( comparison >= 0 );
|
||||
}
|
||||
|
||||
private boolean canViewOddItems( ){
|
||||
return sameLevelOrHigher( RoleLevel.DB_ADMIN ) ;
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class RoleFilter<E extends ResourceBean> extends UnaryFunctor<E,Boolean>{
|
||||
@Override
|
||||
public Boolean fn(E resource) {
|
||||
try{
|
||||
if( resource == null )
|
||||
return canViewOddItems();
|
||||
else
|
||||
log.debug("checking hidden status for \"" + resource.getURI() + "\"");
|
||||
return sameLevelOrHigher( resource.getHiddenFromDisplayBelowRoleLevel() );
|
||||
}catch(RuntimeException th){
|
||||
log.warn("Error checking hidden status for " + resource, th);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class IndividualRoleFilter extends UnaryFunctor<Individual,Boolean>{
|
||||
@Override
|
||||
public Boolean fn(Individual ind){
|
||||
if( ind == null ) {
|
||||
log.debug("checking hidden status for null Individual");
|
||||
return canViewOddItems();
|
||||
}
|
||||
log.debug("checking hidden status for Individual \"" + ind.getName() + "\"");
|
||||
|
||||
try{
|
||||
if( ! sameLevelOrHigher( ind.getHiddenFromDisplayBelowRoleLevel() ) )
|
||||
return false;
|
||||
|
||||
if( FILTER_ON_INDIVIDUAL_VCLASSES ){
|
||||
List<VClass> vclasses = ind.getVClasses(true);
|
||||
|
||||
if( vclasses == null ){
|
||||
VClass clazz = wdf.getVClassDao().getVClassByURI(ind.getVClassURI());
|
||||
if( clazz == null )
|
||||
return canViewOddItems();
|
||||
else
|
||||
return sameLevelOrHigher(clazz.getHiddenFromDisplayBelowRoleLevel() );
|
||||
}
|
||||
|
||||
for( VClass vclass : vclasses ){
|
||||
if( ! sameLevelOrHigher(vclass.getHiddenFromDisplayBelowRoleLevel() ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}catch(RuntimeException ex){
|
||||
log.warn("Error checking hidden status for " + ind.getName() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class DataPropertyStatementRoleFilter<E extends DataPropertyStatement>
|
||||
extends UnaryFunctor<E,Boolean>{
|
||||
@Override
|
||||
public Boolean fn(E dPropStmt) {
|
||||
if( dPropStmt == null ) return false; //don't know why this would happen
|
||||
log.debug("checking hidden status for data property statement \"" + dPropStmt.getDatapropURI() + "\"");
|
||||
try {
|
||||
String propUri = dPropStmt.getDatapropURI();
|
||||
if (propUri == null) {
|
||||
if ( ! canViewOddItems() ){ return false; }
|
||||
} else {
|
||||
DataProperty prop = null;
|
||||
if( dataPropertyMap.containsKey(propUri) ){
|
||||
prop = dataPropertyMap.get(propUri);
|
||||
}else{
|
||||
prop = wdf.getDataPropertyDao().getDataPropertyByURI(propUri);
|
||||
dataPropertyMap.put(propUri, prop);
|
||||
}
|
||||
if( prop == null ) {
|
||||
if( ! canViewOddItems() ){ return false; }
|
||||
}else{
|
||||
if( sameLevelOrHigher( prop.getHiddenFromDisplayBelowRoleLevel() ) == false)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Individual subject = dPropStmt.getIndividual();
|
||||
if( subject == null ) {
|
||||
if( ! canViewOddItems() ){ return false; }
|
||||
}else{
|
||||
if( sameLevelOrHigher( subject.getHiddenFromDisplayBelowRoleLevel() ) == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
if( FILTER_ON_INDIVIDUAL_VCLASSES ){
|
||||
VClass subjectClass =
|
||||
(subject.getVClass() != null ? subject.getVClass() : wdf.getVClassDao().getVClassByURI(subject.getVClassURI()));
|
||||
if( subjectClass == null ){
|
||||
if( ! canViewOddItems() ){ return false; }
|
||||
}else{
|
||||
if( sameLevelOrHigher( subjectClass.getHiddenFromDisplayBelowRoleLevel() ) == false )
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("Error checking hidden status of data property statement \"" + dPropStmt.getDatapropURI() +"\"", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class ObjectPropertyStatementRoleFilter<E extends ObjectPropertyStatement>
|
||||
extends UnaryFunctor<E,Boolean>{
|
||||
@Override
|
||||
public Boolean fn(E stmt) {
|
||||
if( stmt == null ) {
|
||||
log.debug("checking hidden status for null object property statement");
|
||||
return false;
|
||||
}
|
||||
log.debug("checking hidden status for object property statement \"" + stmt.getPropertyURI() + "\"");
|
||||
|
||||
try {
|
||||
ObjectProperty prop = stmt.getProperty();
|
||||
if( prop == null ){
|
||||
String objPropUri = stmt.getPropertyURI();
|
||||
prop = wdf.getObjectPropertyDao().getObjectPropertyByURI(objPropUri);
|
||||
}
|
||||
|
||||
if (prop == null){
|
||||
if (!canViewOddItems()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (sameLevelOrHigher(prop.getHiddenFromDisplayBelowRoleLevel()) == false){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Individual subject =
|
||||
(stmt.getSubject() != null ?
|
||||
stmt.getSubject()
|
||||
: wdf.getIndividualDao().getIndividualByURI( stmt.getSubjectURI()));
|
||||
|
||||
if (subject == null) {
|
||||
if (!canViewOddItems()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (sameLevelOrHigher(subject
|
||||
.getHiddenFromDisplayBelowRoleLevel()) == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
Individual object =
|
||||
(stmt.getObject() != null ?
|
||||
stmt.getObject()
|
||||
: wdf.getIndividualDao().getIndividualByURI( stmt.getObjectURI() ));
|
||||
|
||||
if (object == null) {
|
||||
if (!canViewOddItems()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (sameLevelOrHigher(object
|
||||
.getHiddenFromDisplayBelowRoleLevel()) == false)
|
||||
return false;
|
||||
}
|
||||
|
||||
if( FILTER_ON_INDIVIDUAL_VCLASSES ){
|
||||
VClass subjectClass =
|
||||
(subject.getVClass() != null ? subject.getVClass() : wdf.getVClassDao().getVClassByURI(subject.getVClassURI()));
|
||||
if( subjectClass == null ){
|
||||
if( ! canViewOddItems() ){ return false; }
|
||||
}else{
|
||||
if( sameLevelOrHigher( subjectClass.getHiddenFromDisplayBelowRoleLevel() ) == false )
|
||||
return false;
|
||||
}
|
||||
|
||||
VClass objectClass =
|
||||
(object.getVClass() != null ? object.getVClass() : wdf.getVClassDao().getVClassByURI(object.getVClassURI()));
|
||||
if( objectClass == null ){
|
||||
if( ! canViewOddItems() ){ return false; }
|
||||
}else{
|
||||
if( sameLevelOrHigher( objectClass.getHiddenFromDisplayBelowRoleLevel() ) == false )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("Error checking hidden status of object property statement \"" + stmt.getPropertyURI()+"\"", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
import net.sf.jga.fn.comparison.ComparisonFunctors;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class BaseFilteringTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterMethods(){
|
||||
List numbers = Arrays.asList( 1,2,3,4,5,6,7,8,9,10 );
|
||||
UnaryFunctor<Integer,Boolean> greaterThan3 =
|
||||
ComparisonFunctors.greater(3);
|
||||
|
||||
BaseFiltering b = new BaseFiltering();
|
||||
List filteredNum = b.filter(numbers,greaterThan3);
|
||||
Assert.assertNotNull(filteredNum);
|
||||
Assert.assertTrue("expected 7 found "+filteredNum.size() , filteredNum.size() == 7);
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
# $This file is distributed under the terms of the license in /doc/license.txt$
|
||||
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix mydomain: <http://vivo.mydomain.edu/individual/> .
|
||||
|
||||
### This file is for the test IndividualFilteringTest.java.
|
||||
|
||||
#
|
||||
# Bozo
|
||||
#
|
||||
mydomain:bozo
|
||||
a mydomain:publicClass ;
|
||||
|
||||
mydomain:openDataProperty "open info" ;
|
||||
mydomain:publicDataProperty "public info" ;
|
||||
mydomain:selfDataProperty "self info" ;
|
||||
mydomain:editorDataProperty "editor info" ;
|
||||
mydomain:curatorDataProperty "curator info" ;
|
||||
mydomain:dbaDataProperty "dba info" ;
|
||||
mydomain:hiddenDataProperty "hidden info" ;
|
||||
|
||||
mydomain:openObjectProperty mydomain:openObject ;
|
||||
mydomain:openObjectProperty mydomain:publicObject ;
|
||||
mydomain:openObjectProperty mydomain:selfObject ;
|
||||
mydomain:openObjectProperty mydomain:editorObject ;
|
||||
mydomain:openObjectProperty mydomain:curatorObject ;
|
||||
mydomain:openObjectProperty mydomain:dbaObject ;
|
||||
mydomain:openObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:publicObjectProperty mydomain:openObject ;
|
||||
mydomain:publicObjectProperty mydomain:publicObject ;
|
||||
mydomain:publicObjectProperty mydomain:selfObject ;
|
||||
mydomain:publicObjectProperty mydomain:editorObject ;
|
||||
mydomain:publicObjectProperty mydomain:curatorObject ;
|
||||
mydomain:publicObjectProperty mydomain:dbaObject ;
|
||||
mydomain:publicObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:selfObjectProperty mydomain:openObject ;
|
||||
mydomain:selfObjectProperty mydomain:publicObject ;
|
||||
mydomain:selfObjectProperty mydomain:selfObject ;
|
||||
mydomain:selfObjectProperty mydomain:editorObject ;
|
||||
mydomain:selfObjectProperty mydomain:curatorObject ;
|
||||
mydomain:selfObjectProperty mydomain:dbaObject ;
|
||||
mydomain:selfObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:editorObjectProperty mydomain:openObject ;
|
||||
mydomain:editorObjectProperty mydomain:publicObject ;
|
||||
mydomain:editorObjectProperty mydomain:selfObject ;
|
||||
mydomain:editorObjectProperty mydomain:editorObject ;
|
||||
mydomain:editorObjectProperty mydomain:curatorObject ;
|
||||
mydomain:editorObjectProperty mydomain:dbaObject ;
|
||||
mydomain:editorObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:curatorObjectProperty mydomain:openObject ;
|
||||
mydomain:curatorObjectProperty mydomain:publicObject ;
|
||||
mydomain:curatorObjectProperty mydomain:selfObject ;
|
||||
mydomain:curatorObjectProperty mydomain:editorObject ;
|
||||
mydomain:curatorObjectProperty mydomain:curatorObject ;
|
||||
mydomain:curatorObjectProperty mydomain:dbaObject ;
|
||||
mydomain:curatorObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:dbaObjectProperty mydomain:openObject ;
|
||||
mydomain:dbaObjectProperty mydomain:publicObject ;
|
||||
mydomain:dbaObjectProperty mydomain:selfObject ;
|
||||
mydomain:dbaObjectProperty mydomain:editorObject ;
|
||||
mydomain:dbaObjectProperty mydomain:curatorObject ;
|
||||
mydomain:dbaObjectProperty mydomain:dbaObject ;
|
||||
mydomain:dbaObjectProperty mydomain:hiddenObject ;
|
||||
|
||||
mydomain:hiddenObjectProperty mydomain:openObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:publicObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:selfObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:editorObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:curatorObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:dbaObject ;
|
||||
mydomain:hiddenObjectProperty mydomain:hiddenObject ;
|
||||
.
|
||||
|
||||
#
|
||||
# Objects of object properties
|
||||
#
|
||||
mydomain:openObject
|
||||
a mydomain:openClass ;
|
||||
rdfs:label "open file" ;
|
||||
.
|
||||
mydomain:publicObject
|
||||
a mydomain:publicClass ;
|
||||
rdfs:label "public file" ;
|
||||
.
|
||||
mydomain:selfObject
|
||||
a mydomain:selfClass ;
|
||||
rdfs:label "self file" ;
|
||||
.
|
||||
mydomain:editorObject
|
||||
a mydomain:editorClass ;
|
||||
rdfs:label "editor file" ;
|
||||
.
|
||||
mydomain:curatorObject
|
||||
a mydomain:curatorClass ;
|
||||
rdfs:label "curator file" ;
|
||||
.
|
||||
mydomain:dbaObject
|
||||
a mydomain:dbaClass ;
|
||||
rdfs:label "dba file" ;
|
||||
.
|
||||
mydomain:hiddenObject
|
||||
a mydomain:hiddenClass ;
|
||||
rdfs:label "hidden file" ;
|
||||
.
|
|
@ -1,108 +0,0 @@
|
|||
# $This file is distributed under the terms of the license in /doc/license.txt$
|
||||
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix mydomain: <http://vivo.mydomain.edu/individual/> .
|
||||
@prefix vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
|
||||
@prefix role: <http://vitro.mannlib.cornell.edu/ns/vitro/role#> .
|
||||
|
||||
|
||||
### This file is for the test IndividualFilteringTest.java.
|
||||
|
||||
#
|
||||
# create the data properties
|
||||
#
|
||||
mydomain:openDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
.
|
||||
|
||||
mydomain:publicDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
|
||||
.
|
||||
|
||||
mydomain:selfDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:selfEditor ;
|
||||
.
|
||||
|
||||
mydomain:editorDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:editor ;
|
||||
.
|
||||
|
||||
mydomain:curatorDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:curator ;
|
||||
.
|
||||
|
||||
mydomain:dbaDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:dbAdmin ;
|
||||
.
|
||||
|
||||
mydomain:hiddenDataProperty
|
||||
a owl:DatatypeProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:nobody ;
|
||||
.
|
||||
|
||||
#
|
||||
# create the object properties
|
||||
#
|
||||
mydomain:openObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
.
|
||||
mydomain:publicObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
|
||||
.
|
||||
mydomain:selfObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:selfEditor ;
|
||||
.
|
||||
mydomain:editorObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:editor ;
|
||||
.
|
||||
mydomain:curatorObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:curator ;
|
||||
.
|
||||
mydomain:dbaObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:dbAdmin ;
|
||||
.
|
||||
mydomain:hiddenObjectProperty
|
||||
a owl:ObjectProperty ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:nobody ;
|
||||
.
|
||||
|
||||
#
|
||||
# create the object classes
|
||||
#
|
||||
mydomain:openClass
|
||||
a owl:Class ;
|
||||
.
|
||||
mydomain:publicClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
|
||||
.
|
||||
mydomain:selfClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:selfEditor ;
|
||||
.
|
||||
mydomain:editorClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:editor ;
|
||||
.
|
||||
mydomain:curatorClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:curator ;
|
||||
.
|
||||
mydomain:dbaClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:dbAdmin ;
|
||||
.
|
||||
mydomain:hiddenClass
|
||||
a owl:Class ;
|
||||
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:nobody ;
|
||||
.
|
|
@ -1,526 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HiddenFromDisplayBelowRoleLevelFilter;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
|
||||
/**
|
||||
* Test the filtering of IndividualFiltering.
|
||||
*
|
||||
* There are 6 levels of data hiding - public, selfEditor, editor, curator,
|
||||
* dbAdmin and nobody. We add a 7th case for data which has no explicit hiding
|
||||
* level - it should be treated as public.
|
||||
*
|
||||
* The data files for this test describe an Individual with 7 data properties,
|
||||
* each with a different hiding level, and 49 object properties, showing all
|
||||
* combinations of hiding levels for the property and for the class of the
|
||||
* object.
|
||||
*
|
||||
* There is a flag in HiddenFromDisplayBelowRoleLevelFilter which
|
||||
* enables/disables filtering based on the class of the object. These tests
|
||||
* should work regardless of how that flag is set.
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class IndividualFilteringTest extends AbstractTestClass {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(IndividualFilteringTest.class);
|
||||
|
||||
/**
|
||||
* Where the ontology statements are stored for this test.
|
||||
*/
|
||||
private static final String TBOX_DATA_FILENAME = "IndividualFilteringTest-TBox.n3";
|
||||
|
||||
/**
|
||||
* Where the model statements are stored for this test.
|
||||
*/
|
||||
private static final String ABOX_DATA_FILENAME = "IndividualFilteringTest-Abox.n3";
|
||||
|
||||
/**
|
||||
* The domain where all of the objects and properties are defined.
|
||||
*/
|
||||
private static final String NS = "http://vivo.mydomain.edu/individual/";
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Data elements and creating the model.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The individual we are reading.
|
||||
*/
|
||||
private static final String INDIVIDUAL_URI = mydomain("bozo");
|
||||
|
||||
/**
|
||||
* Data properties to look for.
|
||||
*/
|
||||
private static final String OPEN_DATA_PROPERTY = mydomain("openDataProperty");
|
||||
private static final String PUBLIC_DATA_PROPERTY = mydomain("publicDataProperty");
|
||||
private static final String SELF_DATA_PROPERTY = mydomain("selfDataProperty");
|
||||
private static final String EDITOR_DATA_PROPERTY = mydomain("editorDataProperty");
|
||||
private static final String CURATOR_DATA_PROPERTY = mydomain("curatorDataProperty");
|
||||
private static final String DBA_DATA_PROPERTY = mydomain("dbaDataProperty");
|
||||
private static final String HIDDEN_DATA_PROPERTY = mydomain("hiddenDataProperty");
|
||||
private static final String[] DATA_PROPERTIES = { OPEN_DATA_PROPERTY,
|
||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
||||
CURATOR_DATA_PROPERTY, DBA_DATA_PROPERTY, HIDDEN_DATA_PROPERTY };
|
||||
|
||||
/**
|
||||
* Object properties to look for.
|
||||
*/
|
||||
private static final String OPEN_OBJECT_PROPERTY = mydomain("openObjectProperty");
|
||||
private static final String PUBLIC_OBJECT_PROPERTY = mydomain("publicObjectProperty");
|
||||
private static final String SELF_OBJECT_PROPERTY = mydomain("selfObjectProperty");
|
||||
private static final String EDITOR_OBJECT_PROPERTY = mydomain("editorObjectProperty");
|
||||
private static final String CURATOR_OBJECT_PROPERTY = mydomain("curatorObjectProperty");
|
||||
private static final String DBA_OBJECT_PROPERTY = mydomain("dbaObjectProperty");
|
||||
private static final String HIDDEN_OBJECT_PROPERTY = mydomain("hiddenObjectProperty");
|
||||
private static final String[] OBJECT_PROPERTIES = { OPEN_OBJECT_PROPERTY,
|
||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY,
|
||||
EDITOR_OBJECT_PROPERTY, CURATOR_OBJECT_PROPERTY,
|
||||
DBA_OBJECT_PROPERTY, HIDDEN_OBJECT_PROPERTY };
|
||||
|
||||
/**
|
||||
* Objects to look for.
|
||||
*/
|
||||
private static final String OPEN_OBJECT = mydomain("openObject");
|
||||
private static final String PUBLIC_OBJECT = mydomain("publicObject");
|
||||
private static final String SELF_OBJECT = mydomain("selfObject");
|
||||
private static final String EDITOR_OBJECT = mydomain("editorObject");
|
||||
private static final String CURATOR_OBJECT = mydomain("curatorObject");
|
||||
private static final String DBA_OBJECT = mydomain("dbaObject");
|
||||
private static final String HIDDEN_OBJECT = mydomain("hiddenObject");
|
||||
private static final String[] OBJECTS = { OPEN_OBJECT, PUBLIC_OBJECT,
|
||||
SELF_OBJECT, EDITOR_OBJECT, CURATOR_OBJECT, DBA_OBJECT,
|
||||
HIDDEN_OBJECT };
|
||||
|
||||
private static String mydomain(String localname) {
|
||||
return NS + localname;
|
||||
}
|
||||
|
||||
private static OntModelSelectorImpl ontModelSelector;
|
||||
|
||||
@BeforeClass
|
||||
public static void createTheModels() throws IOException {
|
||||
ontModelSelector = new OntModelSelectorImpl();
|
||||
ontModelSelector.setABoxModel(createAboxModel());
|
||||
ontModelSelector.setTBoxModel(createTboxModel());
|
||||
ontModelSelector.setFullModel(mergeModels(ontModelSelector));
|
||||
}
|
||||
|
||||
private static OntModel createAboxModel() throws IOException {
|
||||
OntModel ontModel = ModelFactory
|
||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||
readFileIntoModel(ontModel, ABOX_DATA_FILENAME, "N3");
|
||||
dumpModel("ABOX", ontModel);
|
||||
return ontModel;
|
||||
}
|
||||
|
||||
private static OntModel createTboxModel() throws IOException {
|
||||
OntModel ontModel = ModelFactory
|
||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||
readFileIntoModel(ontModel, TBOX_DATA_FILENAME, "N3");
|
||||
dumpModel("TBOX", ontModel);
|
||||
return ontModel;
|
||||
}
|
||||
|
||||
private static OntModel mergeModels(OntModelSelectorImpl selector) {
|
||||
OntModel ontModel = ModelFactory
|
||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||
ontModel.add(selector.getABoxModel());
|
||||
ontModel.add(selector.getTBoxModel());
|
||||
return ontModel;
|
||||
}
|
||||
|
||||
private static void readFileIntoModel(OntModel ontModel, String filename,
|
||||
String format) throws IOException {
|
||||
InputStream stream = IndividualFilteringTest.class
|
||||
.getResourceAsStream(filename);
|
||||
ontModel.read(stream, null, format);
|
||||
stream.close();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Set up
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* For each set of tests, specify the login role level and the expected
|
||||
* visible URIs of each type.
|
||||
*/
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> testDataList = new ArrayList<Object[]>();
|
||||
|
||||
testDataList.add(new Object[] { RoleLevel.PUBLIC,
|
||||
set(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY),
|
||||
set(OPEN_OBJECT_PROPERTY, PUBLIC_OBJECT_PROPERTY),
|
||||
set(OPEN_OBJECT, PUBLIC_OBJECT) });
|
||||
|
||||
testDataList.add(new Object[] {
|
||||
RoleLevel.SELF,
|
||||
set(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY,
|
||||
SELF_DATA_PROPERTY),
|
||||
set(OPEN_OBJECT_PROPERTY, PUBLIC_OBJECT_PROPERTY,
|
||||
SELF_OBJECT_PROPERTY),
|
||||
set(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT) });
|
||||
|
||||
testDataList.add(new Object[] {
|
||||
RoleLevel.EDITOR,
|
||||
set(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY,
|
||||
SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY),
|
||||
set(OPEN_OBJECT_PROPERTY, PUBLIC_OBJECT_PROPERTY,
|
||||
SELF_OBJECT_PROPERTY, EDITOR_OBJECT_PROPERTY),
|
||||
set(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT, EDITOR_OBJECT) });
|
||||
|
||||
testDataList.add(new Object[] {
|
||||
RoleLevel.CURATOR,
|
||||
set(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY,
|
||||
SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
||||
CURATOR_DATA_PROPERTY),
|
||||
set(OPEN_OBJECT_PROPERTY, PUBLIC_OBJECT_PROPERTY,
|
||||
SELF_OBJECT_PROPERTY, EDITOR_OBJECT_PROPERTY,
|
||||
CURATOR_OBJECT_PROPERTY),
|
||||
set(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT, EDITOR_OBJECT,
|
||||
CURATOR_OBJECT) });
|
||||
|
||||
testDataList.add(new Object[] {
|
||||
RoleLevel.DB_ADMIN,
|
||||
set(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY,
|
||||
SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
||||
CURATOR_DATA_PROPERTY, DBA_DATA_PROPERTY),
|
||||
set(OPEN_OBJECT_PROPERTY, PUBLIC_OBJECT_PROPERTY,
|
||||
SELF_OBJECT_PROPERTY, EDITOR_OBJECT_PROPERTY,
|
||||
CURATOR_OBJECT_PROPERTY, DBA_OBJECT_PROPERTY),
|
||||
set(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT, EDITOR_OBJECT,
|
||||
CURATOR_OBJECT, DBA_OBJECT) });
|
||||
|
||||
return testDataList;
|
||||
}
|
||||
|
||||
private static <T> Set<T> set(T... elements) {
|
||||
return new HashSet<T>(Arrays.<T> asList(elements));
|
||||
}
|
||||
|
||||
private final RoleLevel loginRole;
|
||||
private final Set<String> expectedDataPropertyUris;
|
||||
private final Set<String> expectedObjectPropertyUris;
|
||||
private final Set<String> expectedObjectUris;
|
||||
|
||||
private WebappDaoFactory wadf;
|
||||
private Individual ind;
|
||||
|
||||
@Before
|
||||
public void createTheFilteredIndividual() {
|
||||
WebappDaoFactory rawWadf = new WebappDaoFactoryJena(ontModelSelector);
|
||||
wadf = new WebappDaoFactoryFiltering(rawWadf,
|
||||
new HiddenFromDisplayBelowRoleLevelFilter(loginRole, rawWadf));
|
||||
ind = wadf.getIndividualDao().getIndividualByURI(INDIVIDUAL_URI);
|
||||
}
|
||||
|
||||
public IndividualFilteringTest(RoleLevel loginRole,
|
||||
Set<String> expectedDataPropertyUris,
|
||||
Set<String> expectedObjectPropertyUris,
|
||||
Set<String> expectedObjectUris) {
|
||||
this.loginRole = loginRole;
|
||||
this.expectedDataPropertyUris = expectedDataPropertyUris;
|
||||
this.expectedObjectPropertyUris = expectedObjectPropertyUris;
|
||||
this.expectedObjectUris = expectedObjectUris;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The tests
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void testGetDataPropertyList() {
|
||||
assertEqualSets("data property list", expectedDataPropertyUris,
|
||||
extractDataPropUris(ind.getDataPropertyList()));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetPopulatedDataPropertyList() {
|
||||
assertEqualSets("populated data property list",
|
||||
expectedDataPropertyUris,
|
||||
extractDataPropUris(ind.getPopulatedDataPropertyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataPropertyStatements() {
|
||||
assertEqualSets("data property statments", expectedDataPropertyUris,
|
||||
extractDataPropStmtUris(ind.getDataPropertyStatements()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataPropertyStatements2() {
|
||||
for (String propUri : DATA_PROPERTIES) {
|
||||
Set<String> uris = extractDataPropStmtUris(ind
|
||||
.getDataPropertyStatements(propUri));
|
||||
if (expectedDataPropertyUris.contains(propUri)) {
|
||||
assertEquals("selected data property: " + propUri,
|
||||
Collections.singleton(propUri), uris);
|
||||
} else {
|
||||
assertEquals("selected data property: " + propUri,
|
||||
Collections.emptySet(), uris);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataPropertyMap() {
|
||||
assertEqualSets("data property map", expectedDataPropertyUris, ind
|
||||
.getDataPropertyMap().keySet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectPropertyList() {
|
||||
assertEqualSets("object properties", expectedObjectPropertyUris,
|
||||
extractObjectPropUris(ind.getObjectPropertyList()));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testPopulatedObjectPropertyList() {
|
||||
assertEqualSets("populated object properties",
|
||||
expectedObjectPropertyUris,
|
||||
extractObjectPropUris(ind.getPopulatedObjectPropertyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* We expect to see an object property statment for each permitted property
|
||||
* and each permitted object. If class filtering is disabled, then all
|
||||
* objects are permitted.
|
||||
*/
|
||||
@Test
|
||||
public void testObjectPropertyStatements() {
|
||||
Collection<String> expectedObjects = filteringOnClasses() ? expectedObjectUris
|
||||
: Arrays.asList(OBJECTS);
|
||||
assertExpectedObjectPropertyStatements("object property statements",
|
||||
expectedObjectPropertyUris, expectedObjects,
|
||||
ind.getObjectPropertyStatements());
|
||||
}
|
||||
|
||||
/**
|
||||
* We expect to see an object property statment for each permitted property
|
||||
* and each permitted object. If class filtering is disabled, then all
|
||||
* objects are permitted.
|
||||
*/
|
||||
@Test
|
||||
public void testObjectPropertyStatements2() {
|
||||
Collection<String> expectedObjects = filteringOnClasses() ? expectedObjectUris
|
||||
: Arrays.asList(OBJECTS);
|
||||
for (String propUri : OBJECT_PROPERTIES) {
|
||||
if (expectedObjectPropertyUris.contains(propUri)) {
|
||||
assertExpectedObjectPropertyStatements(
|
||||
"object property statements for " + propUri,
|
||||
Collections.singleton(propUri), expectedObjects,
|
||||
ind.getObjectPropertyStatements(propUri));
|
||||
} else {
|
||||
assertExpectedObjectPropertyStatements(
|
||||
"object property statements for " + propUri,
|
||||
Collections.<String> emptySet(), expectedObjects,
|
||||
ind.getObjectPropertyStatements(propUri));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectPropertyMap() {
|
||||
assertEqualSets("object property map", expectedObjectPropertyUris, ind
|
||||
.getObjectPropertyMap().keySet());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Are we filtering on VClasses? Use reflection to read that protected
|
||||
* constant.
|
||||
*/
|
||||
private boolean filteringOnClasses() {
|
||||
try {
|
||||
Class<?> clazz = HiddenFromDisplayBelowRoleLevelFilter.class;
|
||||
Field field = clazz
|
||||
.getDeclaredField("FILTER_ON_INDIVIDUAL_VCLASSES");
|
||||
field.setAccessible(true);
|
||||
return (Boolean) field.get(null);
|
||||
} catch (Exception e) {
|
||||
fail("Can't decide on class filtering: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the URIs from these DataProperties */
|
||||
private Set<String> extractDataPropUris(
|
||||
Collection<DataProperty> dataProperties) {
|
||||
Set<String> uris = new TreeSet<String>();
|
||||
if (dataProperties != null) {
|
||||
for (DataProperty dp : dataProperties) {
|
||||
uris.add(dp.getURI());
|
||||
}
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
/** Get the URIs from these DataPropertyStatements */
|
||||
private Set<String> extractDataPropStmtUris(
|
||||
Collection<DataPropertyStatement> dataPropertyStatements) {
|
||||
Set<String> uris = new TreeSet<String>();
|
||||
if (dataPropertyStatements != null) {
|
||||
for (DataPropertyStatement dps : dataPropertyStatements) {
|
||||
uris.add(dps.getDatapropURI());
|
||||
}
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
/** Get the URIs from these ObjectProperties */
|
||||
private Set<String> extractObjectPropUris(
|
||||
Collection<ObjectProperty> objectProperties) {
|
||||
Set<String> uris = new TreeSet<String>();
|
||||
if (objectProperties != null) {
|
||||
for (ObjectProperty op : objectProperties) {
|
||||
uris.add(op.getURI());
|
||||
}
|
||||
}
|
||||
return uris;
|
||||
}
|
||||
|
||||
/**
|
||||
* We expect one statement for each combination of expected object
|
||||
* properties and expected object.
|
||||
*/
|
||||
private void assertExpectedObjectPropertyStatements(String label,
|
||||
Collection<String> expectedProperties,
|
||||
Collection<String> expectedObjects,
|
||||
List<ObjectPropertyStatement> actualStmts) {
|
||||
Set<ObjectPropertyStatementUris> actualStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
||||
for (ObjectPropertyStatement actualStmt : actualStmts) {
|
||||
actualStmtUris.add(new ObjectPropertyStatementUris(actualStmt));
|
||||
}
|
||||
|
||||
Set<ObjectPropertyStatementUris> expectedStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
||||
for (String propertyUri : expectedProperties) {
|
||||
for (String objectUri : expectedObjects) {
|
||||
expectedStmtUris.add(new ObjectPropertyStatementUris(ind
|
||||
.getURI(), propertyUri, objectUri));
|
||||
}
|
||||
}
|
||||
|
||||
assertEqualSets(label, expectedStmtUris, actualStmtUris);
|
||||
}
|
||||
|
||||
private static void dumpModel(String label, OntModel ontModel) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Dumping the " + label + " model:");
|
||||
StmtIterator stmtIt = ontModel.listStatements();
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.next();
|
||||
log.debug("stmt: " + stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture the essence of an ObjectPropertyStatement for comparison and
|
||||
* display.
|
||||
*/
|
||||
private static class ObjectPropertyStatementUris implements
|
||||
Comparable<ObjectPropertyStatementUris> {
|
||||
private final String subjectUri;
|
||||
private final String propertyUri;
|
||||
private final String objectUri;
|
||||
|
||||
ObjectPropertyStatementUris(ObjectPropertyStatement stmt) {
|
||||
this.subjectUri = stmt.getSubjectURI();
|
||||
this.propertyUri = stmt.getPropertyURI();
|
||||
this.objectUri = stmt.getObjectURI();
|
||||
}
|
||||
|
||||
public ObjectPropertyStatementUris(String subjectUri,
|
||||
String propertyUri, String objectUri) {
|
||||
this.subjectUri = subjectUri;
|
||||
this.propertyUri = propertyUri;
|
||||
this.objectUri = objectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ObjectPropertyStatementUris that) {
|
||||
int first = this.subjectUri.compareTo(that.subjectUri);
|
||||
if (first != 0) {
|
||||
return first;
|
||||
}
|
||||
|
||||
int second = this.propertyUri.compareTo(that.propertyUri);
|
||||
if (second != 0) {
|
||||
return second;
|
||||
}
|
||||
|
||||
int third = this.objectUri.compareTo(that.objectUri);
|
||||
return third;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ObjectPropertyStatementUris)) {
|
||||
return false;
|
||||
}
|
||||
ObjectPropertyStatementUris that = (ObjectPropertyStatementUris) o;
|
||||
return this.compareTo(that) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return subjectUri.hashCode() ^ propertyUri.hashCode()
|
||||
^ objectUri.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + subjectUri + " ==> " + propertyUri + " ==> "
|
||||
+ objectUri + "]";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* User: bdc34
|
||||
* Date: Oct 24, 2007
|
||||
* Time: 10:51:01 AM
|
||||
*/
|
||||
public class TabFilteringTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilteringBug1(){
|
||||
/*
|
||||
This test a bug where the vclass listing from the index
|
||||
had a different count than the listing in the auto linked
|
||||
tab.
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
|
||||
public class FiltersTest {
|
||||
|
||||
Boolean ACCEPTED = Boolean.TRUE;
|
||||
Boolean REJECTED = Boolean.FALSE;
|
||||
|
||||
// @Before
|
||||
// public void setUp() throws Exception {
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testTimeFiltersForFutureEvents(){
|
||||
// Tab tab = new Tab();
|
||||
// tab.setDayLimit( 10 );
|
||||
// UnaryFunctor<Individual,Boolean> filter =
|
||||
// FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
//
|
||||
// Individual ind = new IndividualImpl();
|
||||
// DateTime timekey;
|
||||
//
|
||||
// // Allow a slight fudge factor for the time it takes the tests to run.
|
||||
// DateTime now = new DateTime().plusSeconds(1);
|
||||
//
|
||||
// for(int i=1; i < 100 ; i++){
|
||||
// timekey = now.minusDays(i);
|
||||
// ind.setTimekey( timekey.toDate() );
|
||||
// Assert.assertTrue("minus " + i + " days should Reject",
|
||||
// filter.fn( ind ) == REJECTED);
|
||||
// }
|
||||
//
|
||||
// for(int i=0; i< 10 ; i++){
|
||||
// timekey = now.plusDays(i);
|
||||
// ind.setTimekey( timekey.toDate() );
|
||||
// Assert.assertTrue("plus " + i + " days should Accept",
|
||||
// filter.fn( ind ) == ACCEPTED);
|
||||
// }
|
||||
//
|
||||
// timekey = now.plusDays( 10 );
|
||||
// ind.setTimekey( timekey.toDate() );
|
||||
// Assert.assertTrue("plus 10 days should Reject",
|
||||
// filter.fn( ind ) == REJECTED);
|
||||
//
|
||||
// for(int i=10; i < 1000 ; i++){
|
||||
// timekey = now.plusDays(i);
|
||||
// ind.setTimekey( timekey.toDate() );
|
||||
// Assert.assertTrue("plus " + i + " days should Reject",
|
||||
// filter.fn( ind ) == REJECTED);
|
||||
// }
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testTimeFiltersForPastReleases(){
|
||||
// Tab tab = new Tab();
|
||||
// tab.setDayLimit( -10 );
|
||||
// UnaryFunctor<Individual,Boolean> filter =
|
||||
// FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
//
|
||||
// Individual ind = new IndividualImpl();
|
||||
// DateTime sunrise;
|
||||
//
|
||||
// // Allow a slight fudge factor for the time it takes the tests to run.
|
||||
// DateTime now = new DateTime().plusSeconds(1);
|
||||
//
|
||||
// for(int i=1; i < 1000 ; i++){
|
||||
// sunrise = now.plusDays(i);
|
||||
// ind.setSunrise( sunrise.toDate() );
|
||||
// Assert.assertTrue("plus " + i + " days should Reject",
|
||||
// filter.fn( ind ) == REJECTED);
|
||||
// }
|
||||
//
|
||||
// ind.setSunrise( now.minusMinutes(20).toDate() );
|
||||
// Assert.assertTrue("minus 20 minutes should Accept",
|
||||
// filter.fn( ind ) == ACCEPTED);
|
||||
//
|
||||
// for(int i=1; i <= 10 ; i++){
|
||||
// sunrise = now.minusDays(i);
|
||||
// ind.setSunrise( sunrise.toDate() );
|
||||
// Assert.assertTrue("minus " + i + " days should Accept",
|
||||
// filter.fn( ind ) == ACCEPTED);
|
||||
// }
|
||||
//
|
||||
// for(int i=11; i < 100 ; i++){
|
||||
// sunrise = now.minusDays(i);
|
||||
// ind.setSunrise( sunrise.toDate() );
|
||||
// Assert.assertTrue("minus " + i + " days should Reject",
|
||||
// filter.fn( ind ) == REJECTED);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testMarkowitzCase(){
|
||||
// DateTime now = new DateTime().withTime(0, 0, 0, 0);
|
||||
// Date sunrise = now.minusDays(1).toDate();
|
||||
// Date timeKey = now.plusDays(2).toDate();
|
||||
//
|
||||
// Tab tab = new Tab();
|
||||
// tab.setDayLimit( -10 );
|
||||
// UnaryFunctor<Individual,Boolean> filter =
|
||||
// FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
//
|
||||
// Individual ind = new IndividualImpl();
|
||||
// ind.setSunrise( sunrise );
|
||||
// ind.setTimekey( timeKey );
|
||||
//
|
||||
// Assert.assertTrue("Should accept with day limit -10",
|
||||
// filter.fn( ind ) == ACCEPTED);
|
||||
//
|
||||
// tab.setDayLimit( 10 );
|
||||
// filter = FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
//
|
||||
// Assert.assertTrue("Should accept with day limit +10",
|
||||
// filter.fn( ind ) == ACCEPTED );
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -1,962 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
import static edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource.INTERNAL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_CURATOR;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_DBA;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_EDITOR;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_SELF_EDITOR;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.IndividualDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean.AuthenticationSource;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
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.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
|
||||
/**
|
||||
* This test class is written to make it easy to create dozens of tests with
|
||||
* minimal code duplication. That way we can test that Individual A can be
|
||||
* viewed by Curators and DBAs but not by Editors or Self-Editors, etc., etc.,
|
||||
* ad infinitum.
|
||||
*
|
||||
* The class is implemented as a Parameterized JUnit test class. The parameters
|
||||
* are TestData objects, and the class will invoke its single test for one.
|
||||
*
|
||||
* Actually, each parameter is an instance of a TestData sub-class, and the test
|
||||
* method will decide how to handle the data based on the type.
|
||||
*
|
||||
* This gets a little clearer if you start by looking at the section labeled
|
||||
* "the actual test class".
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class HiddenFromDisplayBelowRoleLevelFilterTest extends
|
||||
AbstractTestClass {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(HiddenFromDisplayBelowRoleLevelFilterTest.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// the "framework"
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Each test is driven by an instance of this (actually, of a sub-class).
|
||||
*/
|
||||
private static abstract class TestData {
|
||||
LoginStatusBean loginStatus;
|
||||
|
||||
boolean expectedResult;
|
||||
|
||||
public String getUserUri() {
|
||||
if (loginStatus == null) {
|
||||
return "nobody";
|
||||
} else {
|
||||
return loginStatus.getUserURI();
|
||||
}
|
||||
}
|
||||
|
||||
public RoleLevel getRoleLevel() {
|
||||
return HiddenFromDisplayBelowRoleLevelFilterTest
|
||||
.getRoleLevel(loginStatus);
|
||||
}
|
||||
|
||||
/** A detailed description of the test in case something goes wrong. */
|
||||
public abstract String describeTest();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// data elements
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static final String NS = "http://someDomain/individual/";
|
||||
|
||||
private static final UserAccount USER_SELF = userAccount("userSelf",
|
||||
"self_editor", URI_SELF_EDITOR);
|
||||
private static final UserAccount USER_EDITOR = userAccount("userEditor",
|
||||
"editor", URI_EDITOR);
|
||||
private static final UserAccount USER_CURATOR = userAccount("userCurator",
|
||||
"curator", URI_CURATOR);
|
||||
private static final UserAccount USER_DBA = userAccount(NS + "userDba",
|
||||
"dba", URI_DBA);
|
||||
|
||||
/** Create a User */
|
||||
private static UserAccount userAccount(String uri, String emailAddress,
|
||||
String roleUri) {
|
||||
UserAccount user = new UserAccount();
|
||||
user.setUri(NS + uri);
|
||||
user.setEmailAddress(emailAddress);
|
||||
user.setPermissionSetUris(Collections.singleton(roleUri));
|
||||
return user;
|
||||
}
|
||||
|
||||
private static final UserAccountsDaoStub DAO_USER_ACCOUNT = userAccountsDao(USER_SELF, USER_EDITOR,
|
||||
USER_CURATOR, USER_DBA);
|
||||
|
||||
/** Create the UserAccountsDao */
|
||||
private static UserAccountsDaoStub userAccountsDao(UserAccount... users) {
|
||||
UserAccountsDaoStub dao = new UserAccountsDaoStub();
|
||||
for (UserAccount user : users) {
|
||||
dao.addUser(user);
|
||||
}
|
||||
return dao;
|
||||
}
|
||||
|
||||
private static final LoginStatusBean LOGIN_NONE = null;
|
||||
private static final LoginStatusBean LOGIN_SELF = loginStatusBean(
|
||||
USER_SELF, INTERNAL);
|
||||
private static final LoginStatusBean LOGIN_EDITOR = loginStatusBean(
|
||||
USER_EDITOR, INTERNAL);
|
||||
private static final LoginStatusBean LOGIN_CURATOR = loginStatusBean(
|
||||
USER_CURATOR, INTERNAL);
|
||||
private static final LoginStatusBean LOGIN_DBA = loginStatusBean(USER_DBA,
|
||||
INTERNAL);
|
||||
|
||||
private static LoginStatusBean loginStatusBean(UserAccount user,
|
||||
AuthenticationSource auth) {
|
||||
return new LoginStatusBean(user.getUri(), auth);
|
||||
}
|
||||
|
||||
private static final LoginStatusBean[] LOGINS = new LoginStatusBean[] {
|
||||
LOGIN_NONE, LOGIN_SELF, LOGIN_EDITOR, LOGIN_CURATOR, LOGIN_DBA };
|
||||
|
||||
private static final Individual PUBLIC_INDIVIDUAL = individual(
|
||||
"PUBLIC_individual", RoleLevel.PUBLIC);
|
||||
private static final Individual SELF_INDIVIDUAL = individual(
|
||||
"SELF_individual", RoleLevel.SELF);
|
||||
private static final Individual EDITOR_INDIVIDUAL = individual(
|
||||
"EDITOR_individual", RoleLevel.EDITOR);
|
||||
private static final Individual CURATOR_INDIVIDUAL = individual(
|
||||
"CURATOR_individual", RoleLevel.CURATOR);
|
||||
private static final Individual DBA_INDIVIDUAL = individual(
|
||||
"DBA_individual", RoleLevel.DB_ADMIN);
|
||||
private static final Individual HIDDEN_INDIVIDUAL = individual(
|
||||
"HIDDEN_individual", RoleLevel.NOBODY);
|
||||
|
||||
private static final Individual[] INDIVIDUALS = new Individual[] {
|
||||
PUBLIC_INDIVIDUAL, SELF_INDIVIDUAL, EDITOR_INDIVIDUAL,
|
||||
CURATOR_INDIVIDUAL, DBA_INDIVIDUAL, HIDDEN_INDIVIDUAL };
|
||||
|
||||
/** Create an Individual */
|
||||
private static Individual individual(String moniker,
|
||||
RoleLevel displayThreshhold) {
|
||||
Individual i = new IndividualImpl();
|
||||
i.setURI("uri:" + moniker);
|
||||
i.setHiddenFromDisplayBelowRoleLevel(displayThreshhold);
|
||||
return i;
|
||||
}
|
||||
|
||||
private static final VClass PUBLIC_VCLASS = vClass("PUBLIC_vclass",
|
||||
RoleLevel.PUBLIC);
|
||||
private static final VClass SELF_VCLASS = vClass("SELF_vclass",
|
||||
RoleLevel.SELF);
|
||||
private static final VClass EDITOR_VCLASS = vClass("EDITOR_vclass",
|
||||
RoleLevel.EDITOR);
|
||||
private static final VClass CURATOR_VCLASS = vClass("CURATOR_vclass",
|
||||
RoleLevel.CURATOR);
|
||||
private static final VClass DBA_VCLASS = vClass("DBA_vclass",
|
||||
RoleLevel.DB_ADMIN);
|
||||
private static final VClass HIDDEN_VCLASS = vClass("HIDDEN_vclass",
|
||||
RoleLevel.NOBODY);
|
||||
|
||||
/** Create a VClass */
|
||||
private static VClass vClass(String label, RoleLevel displayThreshhold) {
|
||||
VClass dp = new VClass();
|
||||
dp.setName(label);
|
||||
dp.setHiddenFromDisplayBelowRoleLevel(displayThreshhold);
|
||||
return dp;
|
||||
}
|
||||
|
||||
private static final DataProperty PUBLIC_DATA_PROPERTY = dataProperty(
|
||||
"PUBLIC_data_property", RoleLevel.PUBLIC);
|
||||
private static final DataProperty SELF_DATA_PROPERTY = dataProperty(
|
||||
"SELF_data_property", RoleLevel.SELF);
|
||||
private static final DataProperty EDITOR_DATA_PROPERTY = dataProperty(
|
||||
"EDITOR_data_property", RoleLevel.EDITOR);
|
||||
private static final DataProperty CURATOR_DATA_PROPERTY = dataProperty(
|
||||
"CURATOR_data_property", RoleLevel.CURATOR);
|
||||
private static final DataProperty DBA_DATA_PROPERTY = dataProperty(
|
||||
"DBA_data_property", RoleLevel.DB_ADMIN);
|
||||
private static final DataProperty HIDDEN_DATA_PROPERTY = dataProperty(
|
||||
"HIDDEN_data_property", RoleLevel.NOBODY);
|
||||
|
||||
private static final DataProperty[] DATA_PROPERTIES = new DataProperty[] {
|
||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
||||
CURATOR_DATA_PROPERTY, DBA_DATA_PROPERTY, HIDDEN_DATA_PROPERTY };
|
||||
|
||||
/** Create a DataProperty */
|
||||
private static DataProperty dataProperty(String label,
|
||||
RoleLevel displayThreshhold) {
|
||||
DataProperty dp = new DataProperty();
|
||||
dp.setLabel(label);
|
||||
dp.setURI("uri:" + label);
|
||||
dp.setHiddenFromDisplayBelowRoleLevel(displayThreshhold);
|
||||
return dp;
|
||||
}
|
||||
|
||||
private static final ObjectProperty PUBLIC_OBJECT_PROPERTY = objectProperty(
|
||||
"PUBLIC_object_property", RoleLevel.PUBLIC);
|
||||
private static final ObjectProperty SELF_OBJECT_PROPERTY = objectProperty(
|
||||
"SELF_object_property", RoleLevel.SELF);
|
||||
private static final ObjectProperty EDITOR_OBJECT_PROPERTY = objectProperty(
|
||||
"EDITOR_object_property", RoleLevel.EDITOR);
|
||||
private static final ObjectProperty CURATOR_OBJECT_PROPERTY = objectProperty(
|
||||
"CURATOR_object_property", RoleLevel.CURATOR);
|
||||
private static final ObjectProperty DBA_OBJECT_PROPERTY = objectProperty(
|
||||
"DBA_object_property", RoleLevel.DB_ADMIN);
|
||||
private static final ObjectProperty HIDDEN_OBJECT_PROPERTY = objectProperty(
|
||||
"HIDDEN_object_property", RoleLevel.NOBODY);
|
||||
|
||||
private static final ObjectProperty[] OBJECT_PROPERTIES = new ObjectProperty[] {
|
||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY,
|
||||
EDITOR_OBJECT_PROPERTY, CURATOR_OBJECT_PROPERTY,
|
||||
DBA_OBJECT_PROPERTY, HIDDEN_OBJECT_PROPERTY };
|
||||
|
||||
/** Create a ObjectProperty */
|
||||
private static ObjectProperty objectProperty(String label,
|
||||
RoleLevel displayThreshhold) {
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setLabel(label);
|
||||
op.setURI("uri:" + label);
|
||||
op.setHiddenFromDisplayBelowRoleLevel(displayThreshhold);
|
||||
return op;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// the "tests"
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> testData() {
|
||||
List<Object[]> tests = new ArrayList<Object[]>();
|
||||
|
||||
/*
|
||||
* tests for Individual filter
|
||||
*/
|
||||
// TODO:
|
||||
// HiddenFromDisplayBelowRoleLevelFilter.FILTER_ON_INDIVIDUAL_VCLASSES
|
||||
// is set to false. If it were true, we would need more tests:
|
||||
//
|
||||
// get the list of direct VClasses
|
||||
// if the list is null (maybe filtered out by a previous filter)
|
||||
// - test the VClass from individual.getVClassUri using the Class filter
|
||||
// else
|
||||
// - test each VClass from the list using the Class filter
|
||||
|
||||
tests.add(testIndividual(PUBLIC_INDIVIDUAL, LOGIN_NONE, true));
|
||||
tests.add(testIndividual(PUBLIC_INDIVIDUAL, LOGIN_SELF, true));
|
||||
tests.add(testIndividual(PUBLIC_INDIVIDUAL, LOGIN_EDITOR, true));
|
||||
tests.add(testIndividual(PUBLIC_INDIVIDUAL, LOGIN_CURATOR, true));
|
||||
tests.add(testIndividual(PUBLIC_INDIVIDUAL, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testIndividual(SELF_INDIVIDUAL, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(SELF_INDIVIDUAL, LOGIN_SELF, true));
|
||||
tests.add(testIndividual(SELF_INDIVIDUAL, LOGIN_EDITOR, true));
|
||||
tests.add(testIndividual(SELF_INDIVIDUAL, LOGIN_CURATOR, true));
|
||||
tests.add(testIndividual(SELF_INDIVIDUAL, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testIndividual(EDITOR_INDIVIDUAL, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(EDITOR_INDIVIDUAL, LOGIN_SELF, false));
|
||||
tests.add(testIndividual(EDITOR_INDIVIDUAL, LOGIN_EDITOR, true));
|
||||
tests.add(testIndividual(EDITOR_INDIVIDUAL, LOGIN_CURATOR, true));
|
||||
tests.add(testIndividual(EDITOR_INDIVIDUAL, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testIndividual(CURATOR_INDIVIDUAL, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(CURATOR_INDIVIDUAL, LOGIN_SELF, false));
|
||||
tests.add(testIndividual(CURATOR_INDIVIDUAL, LOGIN_EDITOR, false));
|
||||
tests.add(testIndividual(CURATOR_INDIVIDUAL, LOGIN_CURATOR, true));
|
||||
tests.add(testIndividual(CURATOR_INDIVIDUAL, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testIndividual(DBA_INDIVIDUAL, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(DBA_INDIVIDUAL, LOGIN_SELF, false));
|
||||
tests.add(testIndividual(DBA_INDIVIDUAL, LOGIN_EDITOR, false));
|
||||
tests.add(testIndividual(DBA_INDIVIDUAL, LOGIN_CURATOR, false));
|
||||
tests.add(testIndividual(DBA_INDIVIDUAL, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testIndividual(HIDDEN_INDIVIDUAL, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(HIDDEN_INDIVIDUAL, LOGIN_SELF, false));
|
||||
tests.add(testIndividual(HIDDEN_INDIVIDUAL, LOGIN_EDITOR, false));
|
||||
tests.add(testIndividual(HIDDEN_INDIVIDUAL, LOGIN_CURATOR, false));
|
||||
tests.add(testIndividual(HIDDEN_INDIVIDUAL, LOGIN_DBA, false));
|
||||
|
||||
tests.add(testIndividual(null, LOGIN_NONE, false));
|
||||
tests.add(testIndividual(null, LOGIN_SELF, false));
|
||||
tests.add(testIndividual(null, LOGIN_EDITOR, false));
|
||||
tests.add(testIndividual(null, LOGIN_CURATOR, false));
|
||||
tests.add(testIndividual(null, LOGIN_DBA, true));
|
||||
|
||||
/*
|
||||
* tests for Class Filter
|
||||
*/
|
||||
tests.add(testVClass(PUBLIC_VCLASS, LOGIN_NONE, true));
|
||||
tests.add(testVClass(PUBLIC_VCLASS, LOGIN_SELF, true));
|
||||
tests.add(testVClass(PUBLIC_VCLASS, LOGIN_EDITOR, true));
|
||||
tests.add(testVClass(PUBLIC_VCLASS, LOGIN_CURATOR, true));
|
||||
tests.add(testVClass(PUBLIC_VCLASS, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testVClass(SELF_VCLASS, LOGIN_NONE, false));
|
||||
tests.add(testVClass(SELF_VCLASS, LOGIN_SELF, true));
|
||||
tests.add(testVClass(SELF_VCLASS, LOGIN_EDITOR, true));
|
||||
tests.add(testVClass(SELF_VCLASS, LOGIN_CURATOR, true));
|
||||
tests.add(testVClass(SELF_VCLASS, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testVClass(EDITOR_VCLASS, LOGIN_NONE, false));
|
||||
tests.add(testVClass(EDITOR_VCLASS, LOGIN_SELF, false));
|
||||
tests.add(testVClass(EDITOR_VCLASS, LOGIN_EDITOR, true));
|
||||
tests.add(testVClass(EDITOR_VCLASS, LOGIN_CURATOR, true));
|
||||
tests.add(testVClass(EDITOR_VCLASS, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testVClass(CURATOR_VCLASS, LOGIN_NONE, false));
|
||||
tests.add(testVClass(CURATOR_VCLASS, LOGIN_SELF, false));
|
||||
tests.add(testVClass(CURATOR_VCLASS, LOGIN_EDITOR, false));
|
||||
tests.add(testVClass(CURATOR_VCLASS, LOGIN_CURATOR, true));
|
||||
tests.add(testVClass(CURATOR_VCLASS, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testVClass(DBA_VCLASS, LOGIN_NONE, false));
|
||||
tests.add(testVClass(DBA_VCLASS, LOGIN_SELF, false));
|
||||
tests.add(testVClass(DBA_VCLASS, LOGIN_EDITOR, false));
|
||||
tests.add(testVClass(DBA_VCLASS, LOGIN_CURATOR, false));
|
||||
tests.add(testVClass(DBA_VCLASS, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testVClass(HIDDEN_VCLASS, LOGIN_NONE, false));
|
||||
tests.add(testVClass(HIDDEN_VCLASS, LOGIN_SELF, false));
|
||||
tests.add(testVClass(HIDDEN_VCLASS, LOGIN_EDITOR, false));
|
||||
tests.add(testVClass(HIDDEN_VCLASS, LOGIN_CURATOR, false));
|
||||
tests.add(testVClass(HIDDEN_VCLASS, LOGIN_DBA, false));
|
||||
|
||||
tests.add(testVClass(null, LOGIN_NONE, false));
|
||||
tests.add(testVClass(null, LOGIN_SELF, false));
|
||||
tests.add(testVClass(null, LOGIN_EDITOR, false));
|
||||
tests.add(testVClass(null, LOGIN_CURATOR, false));
|
||||
tests.add(testVClass(null, LOGIN_DBA, true));
|
||||
|
||||
/*
|
||||
* tests for DataProperty filter
|
||||
*/
|
||||
tests.add(testDataProp(PUBLIC_DATA_PROPERTY, LOGIN_NONE, true));
|
||||
tests.add(testDataProp(PUBLIC_DATA_PROPERTY, LOGIN_SELF, true));
|
||||
tests.add(testDataProp(PUBLIC_DATA_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testDataProp(PUBLIC_DATA_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testDataProp(PUBLIC_DATA_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testDataProp(SELF_DATA_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(SELF_DATA_PROPERTY, LOGIN_SELF, true));
|
||||
tests.add(testDataProp(SELF_DATA_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testDataProp(SELF_DATA_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testDataProp(SELF_DATA_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testDataProp(EDITOR_DATA_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(EDITOR_DATA_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testDataProp(EDITOR_DATA_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testDataProp(EDITOR_DATA_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testDataProp(EDITOR_DATA_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testDataProp(CURATOR_DATA_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(CURATOR_DATA_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testDataProp(CURATOR_DATA_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testDataProp(CURATOR_DATA_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testDataProp(CURATOR_DATA_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testDataProp(DBA_DATA_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(DBA_DATA_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testDataProp(DBA_DATA_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testDataProp(DBA_DATA_PROPERTY, LOGIN_CURATOR, false));
|
||||
tests.add(testDataProp(DBA_DATA_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testDataProp(HIDDEN_DATA_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(HIDDEN_DATA_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testDataProp(HIDDEN_DATA_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testDataProp(HIDDEN_DATA_PROPERTY, LOGIN_CURATOR, false));
|
||||
tests.add(testDataProp(HIDDEN_DATA_PROPERTY, LOGIN_DBA, false));
|
||||
|
||||
tests.add(testDataProp(null, LOGIN_NONE, false));
|
||||
tests.add(testDataProp(null, LOGIN_SELF, false));
|
||||
tests.add(testDataProp(null, LOGIN_EDITOR, false));
|
||||
tests.add(testDataProp(null, LOGIN_CURATOR, false));
|
||||
tests.add(testDataProp(null, LOGIN_DBA, true));
|
||||
|
||||
/*
|
||||
* tests for ObjectProperty filter
|
||||
*/
|
||||
tests.add(testObjectProp(PUBLIC_OBJECT_PROPERTY, LOGIN_NONE, true));
|
||||
tests.add(testObjectProp(PUBLIC_OBJECT_PROPERTY, LOGIN_SELF, true));
|
||||
tests.add(testObjectProp(PUBLIC_OBJECT_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testObjectProp(PUBLIC_OBJECT_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testObjectProp(PUBLIC_OBJECT_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testObjectProp(SELF_OBJECT_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(SELF_OBJECT_PROPERTY, LOGIN_SELF, true));
|
||||
tests.add(testObjectProp(SELF_OBJECT_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testObjectProp(SELF_OBJECT_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testObjectProp(SELF_OBJECT_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testObjectProp(EDITOR_OBJECT_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(EDITOR_OBJECT_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testObjectProp(EDITOR_OBJECT_PROPERTY, LOGIN_EDITOR, true));
|
||||
tests.add(testObjectProp(EDITOR_OBJECT_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testObjectProp(EDITOR_OBJECT_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testObjectProp(CURATOR_OBJECT_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(CURATOR_OBJECT_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testObjectProp(CURATOR_OBJECT_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testObjectProp(CURATOR_OBJECT_PROPERTY, LOGIN_CURATOR, true));
|
||||
tests.add(testObjectProp(CURATOR_OBJECT_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testObjectProp(DBA_OBJECT_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(DBA_OBJECT_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testObjectProp(DBA_OBJECT_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testObjectProp(DBA_OBJECT_PROPERTY, LOGIN_CURATOR, false));
|
||||
tests.add(testObjectProp(DBA_OBJECT_PROPERTY, LOGIN_DBA, true));
|
||||
|
||||
tests.add(testObjectProp(HIDDEN_OBJECT_PROPERTY, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(HIDDEN_OBJECT_PROPERTY, LOGIN_SELF, false));
|
||||
tests.add(testObjectProp(HIDDEN_OBJECT_PROPERTY, LOGIN_EDITOR, false));
|
||||
tests.add(testObjectProp(HIDDEN_OBJECT_PROPERTY, LOGIN_CURATOR, false));
|
||||
tests.add(testObjectProp(HIDDEN_OBJECT_PROPERTY, LOGIN_DBA, false));
|
||||
|
||||
tests.add(testObjectProp(null, LOGIN_NONE, false));
|
||||
tests.add(testObjectProp(null, LOGIN_SELF, false));
|
||||
tests.add(testObjectProp(null, LOGIN_EDITOR, false));
|
||||
tests.add(testObjectProp(null, LOGIN_CURATOR, false));
|
||||
tests.add(testObjectProp(null, LOGIN_DBA, true));
|
||||
|
||||
/*
|
||||
* tests for DataPropertyStatementFilter
|
||||
*
|
||||
* Generate most of these tests algorithmically. Use all combinations of
|
||||
* roles for login, Individual and DataProperty.
|
||||
*/
|
||||
// TODO:
|
||||
// HiddenFromDisplayBelowRoleLevelFilter.FILTER_ON_INDIVIDUAL_VCLASSES
|
||||
// is set to false. If it were true, we would need more tests to check
|
||||
// whether the VClasses of both the subject and the predicate are
|
||||
// viewable.
|
||||
|
||||
for (LoginStatusBean login : LOGINS) {
|
||||
for (Individual subject : INDIVIDUALS) {
|
||||
for (DataProperty predicate : DATA_PROPERTIES) {
|
||||
tests.add(testDataPropStmt(
|
||||
login,
|
||||
subject,
|
||||
predicate,
|
||||
expectedResultForDataPropertyStatement(login,
|
||||
subject, predicate)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tests.add(testDataPropStmt(LOGIN_NONE, null, PUBLIC_DATA_PROPERTY,
|
||||
false));
|
||||
tests.add(testDataPropStmt(LOGIN_SELF, null, PUBLIC_DATA_PROPERTY,
|
||||
false));
|
||||
tests.add(testDataPropStmt(LOGIN_EDITOR, null, PUBLIC_DATA_PROPERTY,
|
||||
false));
|
||||
tests.add(testDataPropStmt(LOGIN_CURATOR, null, PUBLIC_DATA_PROPERTY,
|
||||
false));
|
||||
tests.add(testDataPropStmt(LOGIN_DBA, null, PUBLIC_DATA_PROPERTY, true));
|
||||
|
||||
tests.add(testDataPropStmt(LOGIN_NONE, PUBLIC_INDIVIDUAL, null, false));
|
||||
tests.add(testDataPropStmt(LOGIN_SELF, PUBLIC_INDIVIDUAL, null, false));
|
||||
tests.add(testDataPropStmt(LOGIN_EDITOR, PUBLIC_INDIVIDUAL, null, false));
|
||||
tests.add(testDataPropStmt(LOGIN_CURATOR, PUBLIC_INDIVIDUAL, null,
|
||||
false));
|
||||
tests.add(testDataPropStmt(LOGIN_DBA, PUBLIC_INDIVIDUAL, null, true));
|
||||
|
||||
/*
|
||||
* tests for ObjectPropertyStatementFilter
|
||||
*
|
||||
* Generate most of these tests algorithmically. Use all combinations of
|
||||
* roles for login, Individual (twice) and DataProperty.
|
||||
*/
|
||||
// TODO:
|
||||
// HiddenFromDisplayBelowRoleLevelFilter.FILTER_ON_INDIVIDUAL_VCLASSES
|
||||
// is set to false. If it were true, we would need more tests to check
|
||||
// whether the VClasses of the subject, the predicate and the object are
|
||||
// viewable.
|
||||
for (LoginStatusBean login : LOGINS) {
|
||||
for (Individual subject : INDIVIDUALS) {
|
||||
for (Individual object : INDIVIDUALS) {
|
||||
for (ObjectProperty predicate : OBJECT_PROPERTIES) {
|
||||
boolean expectedResult = expectedResultForObjectPropertyStatement(
|
||||
login, subject, predicate, object);
|
||||
|
||||
tests.add(testObjectPropStmt(login, subject, predicate,
|
||||
object, expectedResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tests.add(testObjectPropStmt(LOGIN_NONE, null, PUBLIC_OBJECT_PROPERTY,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_SELF, null, PUBLIC_OBJECT_PROPERTY,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_EDITOR, null,
|
||||
PUBLIC_OBJECT_PROPERTY, PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_CURATOR, null,
|
||||
PUBLIC_OBJECT_PROPERTY, PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_DBA, null, PUBLIC_OBJECT_PROPERTY,
|
||||
PUBLIC_INDIVIDUAL, true));
|
||||
|
||||
tests.add(testObjectPropStmt(LOGIN_NONE, PUBLIC_INDIVIDUAL, null,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_SELF, PUBLIC_INDIVIDUAL, null,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_EDITOR, PUBLIC_INDIVIDUAL, null,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_CURATOR, PUBLIC_INDIVIDUAL, null,
|
||||
PUBLIC_INDIVIDUAL, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_DBA, PUBLIC_INDIVIDUAL, null,
|
||||
PUBLIC_INDIVIDUAL, true));
|
||||
|
||||
tests.add(testObjectPropStmt(LOGIN_NONE, PUBLIC_INDIVIDUAL,
|
||||
PUBLIC_OBJECT_PROPERTY, null, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_SELF, PUBLIC_INDIVIDUAL,
|
||||
PUBLIC_OBJECT_PROPERTY, null, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_EDITOR, PUBLIC_INDIVIDUAL,
|
||||
PUBLIC_OBJECT_PROPERTY, null, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_CURATOR, PUBLIC_INDIVIDUAL,
|
||||
PUBLIC_OBJECT_PROPERTY, null, false));
|
||||
tests.add(testObjectPropStmt(LOGIN_DBA, PUBLIC_INDIVIDUAL,
|
||||
PUBLIC_OBJECT_PROPERTY, null, true));
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the Individual filter.
|
||||
*/
|
||||
private static Object[] testIndividual(Individual individual,
|
||||
LoginStatusBean loginStatus, boolean expectedResult) {
|
||||
IndividualTestData data = new IndividualTestData();
|
||||
data.loginStatus = loginStatus;
|
||||
data.individual = individual;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static class IndividualTestData extends TestData {
|
||||
Individual individual;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "IndividualTest, login=" + getRoleLevel() + "("
|
||||
+ getUserUri() + ")";
|
||||
if (individual == null) {
|
||||
message += ", individual=null";
|
||||
} else {
|
||||
message += ", individual=" + individual.getLocalName();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the VClass filter.
|
||||
*/
|
||||
private static Object[] testVClass(VClass dp, LoginStatusBean loginStatus,
|
||||
boolean expectedResult) {
|
||||
VClassTestData data = new VClassTestData();
|
||||
data.loginStatus = loginStatus;
|
||||
data.vClass = dp;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static class VClassTestData extends TestData {
|
||||
VClass vClass;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "VClassTest, login=" + getRoleLevel() + "("
|
||||
+ getUserUri() + ")";
|
||||
if (vClass == null) {
|
||||
message += ", vClass=null";
|
||||
} else {
|
||||
message += ", vClass=" + vClass.getName();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the DataProperty filter.
|
||||
*/
|
||||
private static Object[] testDataProp(DataProperty dp,
|
||||
LoginStatusBean loginStatus, boolean expectedResult) {
|
||||
DataPropertyTestData data = new DataPropertyTestData();
|
||||
data.loginStatus = loginStatus;
|
||||
data.dataProperty = dp;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static class DataPropertyTestData extends TestData {
|
||||
DataProperty dataProperty;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "DataPropertyTest, login=" + getRoleLevel() + "("
|
||||
+ getUserUri() + ")";
|
||||
if (dataProperty == null) {
|
||||
message += ", dataProperty=null";
|
||||
} else {
|
||||
message += ", dataProperty=" + dataProperty.getLabel();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the ObjectProperty filter.
|
||||
*/
|
||||
private static Object[] testObjectProp(ObjectProperty dp,
|
||||
LoginStatusBean loginStatus, boolean expectedResult) {
|
||||
ObjectPropertyTestData data = new ObjectPropertyTestData();
|
||||
data.loginStatus = loginStatus;
|
||||
data.objectProperty = dp;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static class ObjectPropertyTestData extends TestData {
|
||||
ObjectProperty objectProperty;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "ObjectPropertyTest, login=" + getRoleLevel()
|
||||
+ "(" + getUserUri() + ")";
|
||||
if (objectProperty == null) {
|
||||
message += ", objectProperty=null";
|
||||
} else {
|
||||
message += ", objectProperty=" + objectProperty.getLabel();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the DataPropertyStatement filter.
|
||||
*/
|
||||
private static Object[] testDataPropStmt(LoginStatusBean login,
|
||||
Individual subject, DataProperty predicate, boolean expectedResult) {
|
||||
DataPropertyStatementTestData data = new DataPropertyStatementTestData();
|
||||
data.loginStatus = login;
|
||||
data.subject = subject;
|
||||
data.predicate = predicate;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static boolean expectedResultForDataPropertyStatement(
|
||||
LoginStatusBean login, Individual subject, DataProperty predicate) {
|
||||
RoleLevel loginRole = getRoleLevel(login);
|
||||
RoleLevel subjectRole = subject.getHiddenFromDisplayBelowRoleLevel();
|
||||
RoleLevel predicateRole = predicate
|
||||
.getHiddenFromDisplayBelowRoleLevel();
|
||||
|
||||
// Is the effective login role at least as high as the threshhold roles
|
||||
// for both subject and predicate?
|
||||
return (loginRole.compareTo(subjectRole) >= 0)
|
||||
&& (loginRole.compareTo(predicateRole) >= 0);
|
||||
}
|
||||
|
||||
private static class DataPropertyStatementTestData extends TestData {
|
||||
Individual subject;
|
||||
DataProperty predicate;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "DataPropertyStatementTest, login="
|
||||
+ getRoleLevel() + "(" + getUserUri() + ")";
|
||||
|
||||
if (subject == null) {
|
||||
message += ", subject=null";
|
||||
} else {
|
||||
message += ", subject=" + subject.getLocalName();
|
||||
}
|
||||
|
||||
if (predicate == null) {
|
||||
message += ", predicate=null";
|
||||
} else {
|
||||
message += ", predicate=" + predicate.getLabel();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble the test data to test the ObjectPropertyStatement filter.
|
||||
*/
|
||||
private static Object[] testObjectPropStmt(LoginStatusBean login,
|
||||
Individual subject, ObjectProperty predicate, Individual object,
|
||||
boolean expectedResult) {
|
||||
ObjectPropertyStatementTestData data = new ObjectPropertyStatementTestData();
|
||||
data.loginStatus = login;
|
||||
data.subject = subject;
|
||||
data.predicate = predicate;
|
||||
data.object = object;
|
||||
data.expectedResult = expectedResult;
|
||||
return new Object[] { data };
|
||||
}
|
||||
|
||||
private static boolean expectedResultForObjectPropertyStatement(
|
||||
LoginStatusBean login, Individual subject,
|
||||
ObjectProperty predicate, Individual object) {
|
||||
RoleLevel loginRole = getRoleLevel(login);
|
||||
RoleLevel subjectRole = subject.getHiddenFromDisplayBelowRoleLevel();
|
||||
RoleLevel predicateRole = predicate
|
||||
.getHiddenFromDisplayBelowRoleLevel();
|
||||
RoleLevel objectRole = object.getHiddenFromDisplayBelowRoleLevel();
|
||||
|
||||
// Is the effective login role at least as high as the threshhold roles
|
||||
// for subject, object, and predicate?
|
||||
return (loginRole.compareTo(subjectRole) >= 0)
|
||||
&& (loginRole.compareTo(objectRole) >= 0)
|
||||
&& (loginRole.compareTo(predicateRole) >= 0);
|
||||
}
|
||||
|
||||
private static class ObjectPropertyStatementTestData extends TestData {
|
||||
Individual subject;
|
||||
ObjectProperty predicate;
|
||||
Individual object;
|
||||
|
||||
@Override
|
||||
public String describeTest() {
|
||||
String message = "ObjectPropertyStatementTest, login="
|
||||
+ getRoleLevel() + "(" + getUserUri() + ")";
|
||||
|
||||
if (subject == null) {
|
||||
message += ", subject=null";
|
||||
} else {
|
||||
message += ", subject=" + subject.getLocalName();
|
||||
}
|
||||
|
||||
if (predicate == null) {
|
||||
message += ", predicate=null";
|
||||
} else {
|
||||
message += ", predicate=" + predicate.getLabel();
|
||||
}
|
||||
|
||||
if (object == null) {
|
||||
message += ", object=null";
|
||||
} else {
|
||||
message += ", object=" + object.getLocalName();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
public static RoleLevel getRoleLevel(LoginStatusBean loginStatus) {
|
||||
if (loginStatus == null) {
|
||||
return RoleLevel.PUBLIC;
|
||||
}
|
||||
|
||||
String userUri = loginStatus.getUserURI();
|
||||
if (userUri == null) {
|
||||
return RoleLevel.PUBLIC;
|
||||
}
|
||||
|
||||
UserAccount user = DAO_USER_ACCOUNT.getUserAccountByUri(userUri);
|
||||
if (user == null) {
|
||||
return RoleLevel.PUBLIC;
|
||||
}
|
||||
|
||||
Set<String> roleUris = user.getPermissionSetUris();
|
||||
if (roleUris.contains(URI_DBA)) {
|
||||
return RoleLevel.DB_ADMIN;
|
||||
} else if (roleUris.contains(URI_CURATOR)) {
|
||||
return RoleLevel.CURATOR;
|
||||
} else if (roleUris.contains(URI_EDITOR)) {
|
||||
return RoleLevel.EDITOR;
|
||||
} else if (roleUris.contains(URI_SELF_EDITOR)) {
|
||||
return RoleLevel.SELF;
|
||||
} else {
|
||||
return RoleLevel.PUBLIC;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// the actual test class
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final TestData testData;
|
||||
|
||||
private WebappDaoFactoryStub wdf;
|
||||
private IndividualDaoStub indDao;
|
||||
private DataPropertyDaoStub dpDao;
|
||||
private ObjectPropertyDaoStub opDao;
|
||||
private HiddenFromDisplayBelowRoleLevelFilter filter;
|
||||
|
||||
public HiddenFromDisplayBelowRoleLevelFilterTest(TestData testData) {
|
||||
this.testData = testData;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setLoggingLevel() {
|
||||
// setLoggerLevel(this.getClass(), org.apache.log4j.Level.DEBUG);
|
||||
// setLoggerLevel(HiddenFromDisplayBelowRoleLevelFilter.class,
|
||||
// org.apache.log4j.Level.DEBUG);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createFilter() {
|
||||
wdf = new WebappDaoFactoryStub();
|
||||
|
||||
indDao = new IndividualDaoStub();
|
||||
wdf.setIndividualDao(indDao);
|
||||
|
||||
dpDao = new DataPropertyDaoStub();
|
||||
wdf.setDataPropertyDao(dpDao);
|
||||
|
||||
opDao = new ObjectPropertyDaoStub();
|
||||
wdf.setObjectPropertyDao(opDao);
|
||||
|
||||
filter = new HiddenFromDisplayBelowRoleLevelFilter(
|
||||
this.testData.getRoleLevel(), wdf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runTest() throws Exception {
|
||||
try {
|
||||
if (testData instanceof IndividualTestData) {
|
||||
runIndividualTest();
|
||||
} else if (testData instanceof VClassTestData) {
|
||||
runVClassTest();
|
||||
} else if (testData instanceof DataPropertyTestData) {
|
||||
runDataPropertyTest();
|
||||
} else if (testData instanceof ObjectPropertyTestData) {
|
||||
runObjectPropertyTest();
|
||||
} else if (testData instanceof DataPropertyStatementTestData) {
|
||||
runDataPropertyStatementTest();
|
||||
} else if (testData instanceof ObjectPropertyStatementTestData) {
|
||||
runObjectPropertyStatementTest();
|
||||
} else {
|
||||
fail("Unrecognized test data: " + testData);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
fail("Exception " + e + " in test: " + testData.describeTest());
|
||||
}
|
||||
}
|
||||
|
||||
private void runIndividualTest() {
|
||||
IndividualTestData data = (IndividualTestData) this.testData;
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getIndividualFilter().fn(data.individual);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
|
||||
private void runVClassTest() {
|
||||
VClassTestData data = (VClassTestData) this.testData;
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getClassFilter().fn(data.vClass);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
|
||||
private void runDataPropertyTest() {
|
||||
DataPropertyTestData data = (DataPropertyTestData) this.testData;
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getDataPropertyFilter().fn(data.dataProperty);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
|
||||
private void runObjectPropertyTest() {
|
||||
ObjectPropertyTestData data = (ObjectPropertyTestData) this.testData;
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getObjectPropertyFilter().fn(
|
||||
data.objectProperty);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
|
||||
private void runDataPropertyStatementTest() {
|
||||
DataPropertyStatementTestData data = (DataPropertyStatementTestData) this.testData;
|
||||
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividual(data.subject);
|
||||
if (data.subject != null) {
|
||||
dps.setIndividualURI(data.subject.getURI());
|
||||
indDao.addIndividual(data.subject);
|
||||
}
|
||||
|
||||
if (data.predicate != null) {
|
||||
dps.setDatapropURI(data.predicate.getURI());
|
||||
dpDao.addDataProperty(data.predicate);
|
||||
}
|
||||
|
||||
dps.setData("bogus data");
|
||||
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getDataPropertyStatementFilter().fn(dps);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
|
||||
private void runObjectPropertyStatementTest() {
|
||||
ObjectPropertyStatementTestData data = (ObjectPropertyStatementTestData) this.testData;
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubject(data.subject);
|
||||
if (data.subject != null) {
|
||||
ops.setSubjectURI(data.subject.getURI());
|
||||
indDao.addIndividual(data.subject);
|
||||
}
|
||||
|
||||
ops.setProperty(data.predicate);
|
||||
if (data.predicate != null) {
|
||||
ops.setPropertyURI(data.predicate.getURI());
|
||||
opDao.addObjectProperty(data.predicate);
|
||||
}
|
||||
|
||||
ops.setObject(data.object);
|
||||
if (data.object != null) {
|
||||
ops.setObjectURI(data.object.getURI());
|
||||
indDao.addIndividual(data.object);
|
||||
}
|
||||
|
||||
boolean expected = data.expectedResult;
|
||||
boolean actual = filter.getObjectPropertyStatementFilter().fn(ops);
|
||||
|
||||
log.debug("expect '" + expected + "' for " + data.describeTest());
|
||||
assertEquals(data.describeTest(), expected, actual);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rdf:RDF xmlns:owl="http://www.w3.org/2002/07/owl/"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema/"
|
||||
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema/"
|
||||
xmlns="http://example.org/test/1.0/">
|
||||
|
||||
<owl:ObjectProperty rdf:about="http://example.org/test/1.0/hiddenProp">
|
||||
<rdfs:label>a hidden object property for testing</rdfs:label>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:ObjectProperty rdf:about="http://example.org/test/1.0/nonhiddenProp">
|
||||
<rdfs:label>a publicly visible object property for testing</rdfs:label>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:Class rdf:about="http://example.org/test/1.0/testType">
|
||||
</owl:Class>
|
||||
|
||||
<testType rdf:about="http://example.org/test/1.0/visibleBob">
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</testType>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/hiddenBob">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</rdf:Description>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/visibleKate">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
</rdf:Description>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/hiddenKate">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
Loading…
Add table
Add a link
Reference in a new issue