NIHVIVO-2254 Cosmetic cleanups.
This commit is contained in:
parent
038a876c34
commit
b8d07dc9a8
1 changed files with 96 additions and 209 deletions
|
@ -2,17 +2,13 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel.CURATOR;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel.DB_ADMIN;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel.EDITOR;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel.PUBLIC;
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel.SELF;
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.fail;
|
import static junit.framework.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -69,10 +65,6 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
private static final Log log = LogFactory
|
private static final Log log = LogFactory
|
||||||
.getLog(IndividualFilteringTest.class);
|
.getLog(IndividualFilteringTest.class);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Data elements and creating the model.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where the ontology statements are stored for this test.
|
* Where the ontology statements are stored for this test.
|
||||||
*/
|
*/
|
||||||
|
@ -88,6 +80,10 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
*/
|
*/
|
||||||
private static final String NS = "http://vivo.mydomain.edu/individual/";
|
private static final String NS = "http://vivo.mydomain.edu/individual/";
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Data elements and creating the model.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The individual we are reading.
|
* The individual we are reading.
|
||||||
*/
|
*/
|
||||||
|
@ -140,64 +136,6 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
return NS + localname;
|
return NS + localname;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TestData publicTestData() {
|
|
||||||
TestData data = new TestData(PUBLIC);
|
|
||||||
data.addExpectedDataProperties(OPEN_DATA_PROPERTY, PUBLIC_DATA_PROPERTY);
|
|
||||||
data.addExpectedObjectProperties(OPEN_OBJECT_PROPERTY,
|
|
||||||
PUBLIC_OBJECT_PROPERTY);
|
|
||||||
data.addExpectedObjects(OPEN_OBJECT, PUBLIC_OBJECT);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TestData selfTestData() {
|
|
||||||
TestData data = new TestData(SELF);
|
|
||||||
data.addExpectedDataProperties(OPEN_DATA_PROPERTY,
|
|
||||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY);
|
|
||||||
data.addExpectedObjectProperties(OPEN_OBJECT_PROPERTY,
|
|
||||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY);
|
|
||||||
data.addExpectedObjects(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TestData editorTestData() {
|
|
||||||
TestData data = new TestData(EDITOR);
|
|
||||||
data.addExpectedDataProperties(OPEN_DATA_PROPERTY,
|
|
||||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY);
|
|
||||||
data.addExpectedObjectProperties(OPEN_OBJECT_PROPERTY,
|
|
||||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY,
|
|
||||||
EDITOR_OBJECT_PROPERTY);
|
|
||||||
data.addExpectedObjects(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT,
|
|
||||||
EDITOR_OBJECT);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TestData curatorTestData() {
|
|
||||||
TestData data = new TestData(CURATOR);
|
|
||||||
data.addExpectedDataProperties(OPEN_DATA_PROPERTY,
|
|
||||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
|
||||||
CURATOR_DATA_PROPERTY);
|
|
||||||
data.addExpectedObjectProperties(OPEN_OBJECT_PROPERTY,
|
|
||||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY,
|
|
||||||
EDITOR_OBJECT_PROPERTY, CURATOR_OBJECT_PROPERTY);
|
|
||||||
data.addExpectedObjects(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT,
|
|
||||||
EDITOR_OBJECT, CURATOR_OBJECT);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TestData dbaTestData() {
|
|
||||||
TestData data = new TestData(DB_ADMIN);
|
|
||||||
data.addExpectedDataProperties(OPEN_DATA_PROPERTY,
|
|
||||||
PUBLIC_DATA_PROPERTY, SELF_DATA_PROPERTY, EDITOR_DATA_PROPERTY,
|
|
||||||
CURATOR_DATA_PROPERTY, DBA_DATA_PROPERTY);
|
|
||||||
data.addExpectedObjectProperties(OPEN_OBJECT_PROPERTY,
|
|
||||||
PUBLIC_OBJECT_PROPERTY, SELF_OBJECT_PROPERTY,
|
|
||||||
EDITOR_OBJECT_PROPERTY, CURATOR_OBJECT_PROPERTY,
|
|
||||||
DBA_OBJECT_PROPERTY);
|
|
||||||
data.addExpectedObjects(OPEN_OBJECT, PUBLIC_OBJECT, SELF_OBJECT,
|
|
||||||
EDITOR_OBJECT, CURATOR_OBJECT, DBA_OBJECT);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static OntModelSelectorImpl ontModelSelector;
|
private static OntModelSelectorImpl ontModelSelector;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -212,28 +150,23 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
OntModel ontModel = ModelFactory
|
OntModel ontModel = ModelFactory
|
||||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||||
readFileIntoModel(ontModel, ABOX_DATA_FILENAME, "N3");
|
readFileIntoModel(ontModel, ABOX_DATA_FILENAME, "N3");
|
||||||
|
dumpModel("ABOX", ontModel);
|
||||||
dumpModel(ontModel);
|
|
||||||
|
|
||||||
return ontModel;
|
return ontModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OntModel createTboxModel() throws IOException {
|
private static OntModel createTboxModel() throws IOException {
|
||||||
OntModel ontModel = ModelFactory
|
OntModel ontModel = ModelFactory
|
||||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||||
|
|
||||||
readFileIntoModel(ontModel, TBOX_DATA_FILENAME, "N3");
|
readFileIntoModel(ontModel, TBOX_DATA_FILENAME, "N3");
|
||||||
|
dumpModel("TBOX", ontModel);
|
||||||
return ontModel;
|
return ontModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OntModel mergeModels(OntModelSelectorImpl selector) {
|
private static OntModel mergeModels(OntModelSelectorImpl selector) {
|
||||||
OntModel ontModel = ModelFactory
|
OntModel ontModel = ModelFactory
|
||||||
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||||
|
|
||||||
ontModel.add(selector.getABoxModel());
|
ontModel.add(selector.getABoxModel());
|
||||||
ontModel.add(selector.getTBoxModel());
|
ontModel.add(selector.getTBoxModel());
|
||||||
|
|
||||||
return ontModel;
|
return ontModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,17 +179,72 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Set up for each test
|
// Set up
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each set of tests, specify the login role level and the expected
|
||||||
|
* visible URIs of each type.
|
||||||
|
*/
|
||||||
@Parameters
|
@Parameters
|
||||||
public static Collection<Object[]> data() {
|
public static Collection<Object[]> data() {
|
||||||
return Arrays.asList(new Object[][] { { publicTestData() },
|
List<Object[]> testDataList = new ArrayList<Object[]>();
|
||||||
{ selfTestData() }, { editorTestData() },
|
|
||||||
{ curatorTestData() }, { dbaTestData() } });
|
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 final TestData testData;
|
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 WebappDaoFactory wadf;
|
||||||
private Individual ind;
|
private Individual ind;
|
||||||
|
|
||||||
|
@ -264,13 +252,18 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
public void createTheFilteredIndividual() {
|
public void createTheFilteredIndividual() {
|
||||||
WebappDaoFactory rawWadf = new WebappDaoFactoryJena(ontModelSelector);
|
WebappDaoFactory rawWadf = new WebappDaoFactoryJena(ontModelSelector);
|
||||||
wadf = new WebappDaoFactoryFiltering(rawWadf,
|
wadf = new WebappDaoFactoryFiltering(rawWadf,
|
||||||
new HiddenFromDisplayBelowRoleLevelFilter(testData.loginRole,
|
new HiddenFromDisplayBelowRoleLevelFilter(loginRole, rawWadf));
|
||||||
rawWadf));
|
|
||||||
ind = wadf.getIndividualDao().getIndividualByURI(INDIVIDUAL_URI);
|
ind = wadf.getIndividualDao().getIndividualByURI(INDIVIDUAL_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndividualFilteringTest(TestData testData) {
|
public IndividualFilteringTest(RoleLevel loginRole,
|
||||||
this.testData = testData;
|
Set<String> expectedDataPropertyUris,
|
||||||
|
Set<String> expectedObjectPropertyUris,
|
||||||
|
Set<String> expectedObjectUris) {
|
||||||
|
this.loginRole = loginRole;
|
||||||
|
this.expectedDataPropertyUris = expectedDataPropertyUris;
|
||||||
|
this.expectedObjectPropertyUris = expectedObjectPropertyUris;
|
||||||
|
this.expectedObjectUris = expectedObjectUris;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -279,22 +272,20 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDataPropertyList() {
|
public void testGetDataPropertyList() {
|
||||||
assertEqualSets("data property list",
|
assertEqualSets("data property list", expectedDataPropertyUris,
|
||||||
testData.expectedDataPropertyUris,
|
|
||||||
extractDataPropUris(ind.getDataPropertyList()));
|
extractDataPropUris(ind.getDataPropertyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPopulatedDataPropertyList() {
|
public void testGetPopulatedDataPropertyList() {
|
||||||
assertEqualSets("populated data property list",
|
assertEqualSets("populated data property list",
|
||||||
testData.expectedDataPropertyUris,
|
expectedDataPropertyUris,
|
||||||
extractDataPropUris(ind.getPopulatedDataPropertyList()));
|
extractDataPropUris(ind.getPopulatedDataPropertyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataPropertyStatements() {
|
public void testDataPropertyStatements() {
|
||||||
assertEqualSets("data property statments",
|
assertEqualSets("data property statments", expectedDataPropertyUris,
|
||||||
testData.expectedDataPropertyUris,
|
|
||||||
extractDataPropStmtUris(ind.getDataPropertyStatements()));
|
extractDataPropStmtUris(ind.getDataPropertyStatements()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +294,7 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
for (String propUri : DATA_PROPERTIES) {
|
for (String propUri : DATA_PROPERTIES) {
|
||||||
Set<String> uris = extractDataPropStmtUris(ind
|
Set<String> uris = extractDataPropStmtUris(ind
|
||||||
.getDataPropertyStatements(propUri));
|
.getDataPropertyStatements(propUri));
|
||||||
if (testData.expectedDataPropertyUris.contains(propUri)) {
|
if (expectedDataPropertyUris.contains(propUri)) {
|
||||||
assertEquals("selected data property: " + propUri,
|
assertEquals("selected data property: " + propUri,
|
||||||
Collections.singleton(propUri), uris);
|
Collections.singleton(propUri), uris);
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,21 +306,20 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDataPropertyMap() {
|
public void testDataPropertyMap() {
|
||||||
assertEqualSets("data property map", testData.expectedDataPropertyUris,
|
assertEqualSets("data property map", expectedDataPropertyUris, ind
|
||||||
ind.getDataPropertyMap().keySet());
|
.getDataPropertyMap().keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testObjectPropertyList() {
|
public void testObjectPropertyList() {
|
||||||
assertEqualSets("object properties",
|
assertEqualSets("object properties", expectedObjectPropertyUris,
|
||||||
testData.expectedObjectPropertyUris,
|
|
||||||
extractObjectPropUris(ind.getObjectPropertyList()));
|
extractObjectPropUris(ind.getObjectPropertyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPopulatedObjectPropertyList() {
|
public void testPopulatedObjectPropertyList() {
|
||||||
assertEqualSets("populated object properties",
|
assertEqualSets("populated object properties",
|
||||||
testData.expectedObjectPropertyUris,
|
expectedObjectPropertyUris,
|
||||||
extractObjectPropUris(ind.getPopulatedObjectPropertyList()));
|
extractObjectPropUris(ind.getPopulatedObjectPropertyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,10 +330,10 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testObjectPropertyStatements() {
|
public void testObjectPropertyStatements() {
|
||||||
Collection<String> expectedObjects = filteringOnClasses() ? testData.expectedObjectUris
|
Collection<String> expectedObjects = filteringOnClasses() ? expectedObjectUris
|
||||||
: Arrays.asList(OBJECTS);
|
: Arrays.asList(OBJECTS);
|
||||||
assertExpectedObjectPropertyStatements("object property statements",
|
assertExpectedObjectPropertyStatements("object property statements",
|
||||||
testData.expectedObjectPropertyUris, expectedObjects,
|
expectedObjectPropertyUris, expectedObjects,
|
||||||
ind.getObjectPropertyStatements());
|
ind.getObjectPropertyStatements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,10 +344,10 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testObjectPropertyStatements2() {
|
public void testObjectPropertyStatements2() {
|
||||||
Collection<String> expectedObjects = filteringOnClasses() ? testData.expectedObjectUris
|
Collection<String> expectedObjects = filteringOnClasses() ? expectedObjectUris
|
||||||
: Arrays.asList(OBJECTS);
|
: Arrays.asList(OBJECTS);
|
||||||
for (String propUri : OBJECT_PROPERTIES) {
|
for (String propUri : OBJECT_PROPERTIES) {
|
||||||
if (testData.expectedObjectPropertyUris.contains(propUri)) {
|
if (expectedObjectPropertyUris.contains(propUri)) {
|
||||||
assertExpectedObjectPropertyStatements(
|
assertExpectedObjectPropertyStatements(
|
||||||
"object property statements for " + propUri,
|
"object property statements for " + propUri,
|
||||||
Collections.singleton(propUri), expectedObjects,
|
Collections.singleton(propUri), expectedObjects,
|
||||||
|
@ -373,9 +363,8 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testObjectPropertyMap() {
|
public void testObjectPropertyMap() {
|
||||||
assertEqualSets("object property map",
|
assertEqualSets("object property map", expectedObjectPropertyUris, ind
|
||||||
testData.expectedObjectPropertyUris, ind.getObjectPropertyMap()
|
.getObjectPropertyMap().keySet());
|
||||||
.keySet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -435,25 +424,13 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
return uris;
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the URIs from these DataPropertyStatements */
|
|
||||||
private Set<String> extractObjectPropStmtUris(
|
|
||||||
Collection<ObjectPropertyStatement> objectPropertyStatements) {
|
|
||||||
Set<String> uris = new TreeSet<String>();
|
|
||||||
if (objectPropertyStatements != null) {
|
|
||||||
for (ObjectPropertyStatement ops : objectPropertyStatements) {
|
|
||||||
uris.add(ops.getPropertyURI());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We expect one statement for each combination of expected object
|
* We expect one statement for each combination of expected object
|
||||||
* properties and expected object.
|
* properties and expected object.
|
||||||
*/
|
*/
|
||||||
private void assertExpectedObjectPropertyStatements(String label,
|
private void assertExpectedObjectPropertyStatements(String label,
|
||||||
Collection<String> expectedPropertyUris,
|
Collection<String> expectedProperties,
|
||||||
Collection<String> expectedObjectUris,
|
Collection<String> expectedObjects,
|
||||||
List<ObjectPropertyStatement> actualStmts) {
|
List<ObjectPropertyStatement> actualStmts) {
|
||||||
Set<ObjectPropertyStatementUris> actualStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
Set<ObjectPropertyStatementUris> actualStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
||||||
for (ObjectPropertyStatement actualStmt : actualStmts) {
|
for (ObjectPropertyStatement actualStmt : actualStmts) {
|
||||||
|
@ -461,8 +438,8 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ObjectPropertyStatementUris> expectedStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
Set<ObjectPropertyStatementUris> expectedStmtUris = new HashSet<ObjectPropertyStatementUris>();
|
||||||
for (String propertyUri : expectedPropertyUris) {
|
for (String propertyUri : expectedProperties) {
|
||||||
for (String objectUri : expectedObjectUris) {
|
for (String objectUri : expectedObjects) {
|
||||||
expectedStmtUris.add(new ObjectPropertyStatementUris(ind
|
expectedStmtUris.add(new ObjectPropertyStatementUris(ind
|
||||||
.getURI(), propertyUri, objectUri));
|
.getURI(), propertyUri, objectUri));
|
||||||
}
|
}
|
||||||
|
@ -471,9 +448,9 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
assertEqualSets(label, expectedStmtUris, actualStmtUris);
|
assertEqualSets(label, expectedStmtUris, actualStmtUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dumpModel(OntModel ontModel) {
|
private static void dumpModel(String label, OntModel ontModel) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Dumping the model:");
|
log.debug("Dumping the " + label + " model:");
|
||||||
StmtIterator stmtIt = ontModel.listStatements();
|
StmtIterator stmtIt = ontModel.listStatements();
|
||||||
while (stmtIt.hasNext()) {
|
while (stmtIt.hasNext()) {
|
||||||
Statement stmt = stmtIt.next();
|
Statement stmt = stmtIt.next();
|
||||||
|
@ -482,96 +459,6 @@ public class IndividualFilteringTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The testing parameter. Each different role level will have different
|
|
||||||
* expectations of visible properties and objects.
|
|
||||||
*/
|
|
||||||
private static class TestData {
|
|
||||||
final RoleLevel loginRole;
|
|
||||||
final Set<String> expectedDataPropertyUris = new TreeSet<String>();
|
|
||||||
final Set<String> expectedObjectPropertyUris = new TreeSet<String>();
|
|
||||||
final Set<String> expectedObjectUris = new TreeSet<String>();
|
|
||||||
|
|
||||||
public TestData(RoleLevel loginRole) {
|
|
||||||
this.loginRole = loginRole;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addExpectedDataProperties(String... uris) {
|
|
||||||
expectedDataPropertyUris.addAll(Arrays.asList(uris));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addExpectedObjectProperties(String... uris) {
|
|
||||||
expectedObjectPropertyUris.addAll(Arrays.asList(uris));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addExpectedObjects(String... uris) {
|
|
||||||
expectedObjectUris.addAll(Arrays.asList(uris));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Capture the essence of an DataPropertyStatement for comparison and
|
|
||||||
* display.
|
|
||||||
*/
|
|
||||||
private static class DataPropertyStatementUris implements
|
|
||||||
Comparable<DataPropertyStatementUris> {
|
|
||||||
private final String subjectUri;
|
|
||||||
private final String propertyUri;
|
|
||||||
private final String data;
|
|
||||||
|
|
||||||
DataPropertyStatementUris(DataPropertyStatement stmt) {
|
|
||||||
this.subjectUri = stmt.getIndividualURI();
|
|
||||||
this.propertyUri = stmt.getDatapropURI();
|
|
||||||
this.data = stmt.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataPropertyStatementUris(String subjectUri, String propertyUri,
|
|
||||||
String data) {
|
|
||||||
this.subjectUri = subjectUri;
|
|
||||||
this.propertyUri = propertyUri;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(DataPropertyStatementUris 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.data.compareTo(that.data);
|
|
||||||
return third;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof DataPropertyStatementUris)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DataPropertyStatementUris that = (DataPropertyStatementUris) o;
|
|
||||||
return this.compareTo(that) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return subjectUri.hashCode() ^ propertyUri.hashCode()
|
|
||||||
^ data.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "[" + subjectUri + " ==> " + propertyUri + " ==> " + data
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture the essence of an ObjectPropertyStatement for comparison and
|
* Capture the essence of an ObjectPropertyStatement for comparison and
|
||||||
* display.
|
* display.
|
||||||
|
|
Loading…
Add table
Reference in a new issue