Merge commit 'f129f727a7
' into dev-isf
This commit is contained in:
commit
a520878b1d
122 changed files with 6031 additions and 3353 deletions
|
@ -0,0 +1,156 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AllRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AnyRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AuthorizedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.UnauthorizedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
|
||||
public class PolicyListTest {
|
||||
|
||||
@Test
|
||||
public void basicPolicyListTest() {
|
||||
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
PolicyDecision decision = policy.isAuthorized(null, new UnauthorizedAction());
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
decision = policy.isAuthorized(null, new AuthorizedAction());
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the handling of the AnyRequestedAction by the PolicyList.
|
||||
*/
|
||||
@Test
|
||||
public void anyActionTest(){
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
|
||||
AnyRequestedAction act = new AnyRequestedAction( new UnauthorizedAction() );
|
||||
PolicyDecision decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction() , new UnauthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new UnauthorizedAction(),new UnauthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction(),new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new UnauthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new UnauthorizedAction(),new AuthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AnyRequestedAction( new AuthorizedAction(),new AuthorizedAction(),new AuthorizedAction());
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the handling of the AllRequestedAction by the PolicyList.
|
||||
*/
|
||||
@Test
|
||||
public void andActionTest(){
|
||||
List<PolicyIface> polis = new ArrayList<PolicyIface>();
|
||||
polis.add( new SimplePolicy() );
|
||||
PolicyIface policy = new PolicyList( polis );
|
||||
|
||||
AllRequestedAction act = new AllRequestedAction( new UnauthorizedAction(), new UnauthorizedAction(), new UnauthorizedAction());
|
||||
PolicyDecision decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new UnauthorizedAction() , new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new AuthorizedAction() ,new UnauthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.UNAUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
|
||||
act = new AllRequestedAction( new AuthorizedAction() , new AuthorizedAction(), new AuthorizedAction() );
|
||||
decision = policy.isAuthorized(null, act);
|
||||
Assert.assertNotNull( decision );
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, decision.getAuthorized() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* policy that only responds to Unauthorized and Authorized actions.
|
||||
*/
|
||||
public class SimplePolicy implements PolicyIface {
|
||||
|
||||
@Override
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
if( whatToAuth instanceof UnauthorizedAction )
|
||||
return new BasicPolicyDecision( Authorization.UNAUTHORIZED, "SimplePolicy unauthorized");
|
||||
if( whatToAuth instanceof AuthorizedAction )
|
||||
return new BasicPolicyDecision( Authorization.AUTHORIZED, "SimplePolicy authorized");
|
||||
else
|
||||
return new BasicPolicyDecision(Authorization.INCONCLUSIVE, "SimplePolicy INCONCLUSIVE");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.github.jsonldjava.core.JSONLD;
|
||||
import com.github.jsonldjava.core.JSONLDProcessingError;
|
||||
import com.github.jsonldjava.impl.JenaRDFParser;
|
||||
import com.github.jsonldjava.utils.JSONUtils;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
public class SparqlQueryServletTest {
|
||||
|
||||
@Test
|
||||
public void testJSONLD() throws JSONLDProcessingError {
|
||||
//just check if we can use JSONLD-JAVA
|
||||
|
||||
final String turtle = "@prefix const: <http://foo.com/> .\n"
|
||||
+ "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
|
||||
+ "<http://localhost:8080/foo1> const:code \"123\" .\n"
|
||||
+ "<http://localhost:8080/foo2> const:code \"ABC\"^^xsd:string .\n";
|
||||
|
||||
final List<Map<String, Object>> expected = new ArrayList<Map<String, Object>>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@id", "http://localhost:8080/foo1");
|
||||
put("http://foo.com/code", new ArrayList<Object>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@value", "123");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@id", "http://localhost:8080/foo2");
|
||||
put("http://foo.com/code", new ArrayList<Object>() {
|
||||
{
|
||||
add(new LinkedHashMap<String, Object>() {
|
||||
{
|
||||
put("@value", "ABC");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
final Model modelResult = ModelFactory.createDefaultModel().read(
|
||||
new ByteArrayInputStream(turtle.getBytes()), "", "TURTLE");
|
||||
final JenaRDFParser parser = new JenaRDFParser();
|
||||
final Object json = JSONLD.fromRDF(modelResult, parser);
|
||||
|
||||
assertTrue(JSONUtils.equals(json, expected));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@ import stubs.javax.servlet.http.HttpServletResponseStub;
|
|||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSets;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ public class ProgramLoginTest extends AbstractTestClass {
|
|||
user.setEmailAddress(name);
|
||||
user.setUri(uri);
|
||||
user.setPermissionSetUris(Collections
|
||||
.singleton(PermissionSetsLoader.URI_DBA));
|
||||
.singleton(PermissionSets.URI_DBA));
|
||||
user.setMd5Password(Authenticator.applyMd5Encoding(password));
|
||||
user.setLoginCount(loginCount);
|
||||
user.setPasswordChangeRequired(loginCount == 0);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_DBA;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSetsLoader.URI_SELF_EDITOR;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSets.URI_DBA;
|
||||
import static edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionSets.URI_SELF_EDITOR;
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State.FORCED_PASSWORD_CHANGE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State.LOGGING_IN;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
|
@ -3,12 +3,21 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.ApplicationDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||
|
||||
public class UrlBuilderTest extends AbstractTestClass {
|
||||
|
||||
|
@ -76,4 +85,81 @@ public class UrlBuilderTest extends AbstractTestClass {
|
|||
String vClassUriEncoded = "http%3A%2F%2Fvivoweb.org%2Fontology%2Fcore%23FacultyMember%E2%98%85";
|
||||
Assert.assertEquals(vClassUri, UrlBuilder.urlDecode(vClassUriEncoded));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetIndividualProfileURI(){
|
||||
VitroRequest vreq = makeMockVitroRequest( "http://example.com/individual/");
|
||||
UrlBuilder.contextPath = "http://example.com";
|
||||
|
||||
String uri = "http://example.com/individual/n2343";
|
||||
String url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||
Assert.assertEquals("http://example.com/individual/n2343", url);
|
||||
|
||||
uri = "http://example.com/individual/bob";
|
||||
url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||
Assert.assertEquals("http://example.com/individual/bob",url);
|
||||
|
||||
uri = "http://nondefaultNS.com/individual/n2343";
|
||||
url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||
Assert.assertEquals("http://example.com/individual?uri=" + URLEncoder.encode(uri), url);
|
||||
|
||||
uri = "http://example.com/individual#n2343";
|
||||
url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||
Assert.assertEquals("http://example.com/individual?uri=" + URLEncoder.encode(uri), url);
|
||||
|
||||
uri = "http://example.com/individual/5LNCannotStartWithNumber";
|
||||
url = UrlBuilder.getIndividualProfileUrl(uri, vreq);
|
||||
Assert.assertEquals("http://example.com/individual?uri=" + URLEncoder.encode(uri), url);
|
||||
}
|
||||
|
||||
protected VitroRequest makeMockVitroRequest( final String defaultNS){
|
||||
HttpServletRequest req = createMock( HttpServletRequest.class );
|
||||
return new VitroRequest(req){
|
||||
|
||||
@Override
|
||||
public String getParameter(String key){ return null; }
|
||||
|
||||
@Override
|
||||
public WebappDaoFactory getWebappDaoFactory(){
|
||||
return makeMockWDF(defaultNS);
|
||||
}
|
||||
};
|
||||
}
|
||||
protected WebappDaoFactoryStub makeMockWDF( String defaultNS){
|
||||
WebappDaoFactoryStub wdf = new WebappDaoFactoryStub();
|
||||
wdf.setDefaultNamespace("http://example.com/individual/");
|
||||
ApplicationDaoStub aDao = new ApplicationDaoStub(){
|
||||
@Override
|
||||
public boolean isExternallyLinkedNamespace(String ns){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
wdf.setApplicationDao( aDao );
|
||||
return wdf;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsUriInDefaultNamespace(){
|
||||
String[][] examples = {
|
||||
{ "http://example.com/individual/n3234", "http://example.com/individual/"},
|
||||
{ "http://example.com/individual#n3234", "http://example.com/individual#"},
|
||||
{ "http://example.com:8080/individual/n3234", "http://example.com:8080/individual/"},
|
||||
{ "http://example.com:8080/individual#n3234", "http://example.com:8080/individual#"}
|
||||
};
|
||||
|
||||
for( String[] example : examples ){
|
||||
Assert.assertTrue("expected '"+ example[0] + "' to be in the default NS of '"+example[1]+"'",
|
||||
UrlBuilder.isUriInDefaultNamespace(example[0], example[1]));
|
||||
}
|
||||
|
||||
String[][] counterExamples = {
|
||||
{ "http://example.com/individual/5LNCannotStartWithNumber", "http://example.com/individual/" }
|
||||
};
|
||||
for( String[] example : counterExamples ){
|
||||
Assert.assertFalse("expected '"+ example[0] + "' to NOT be in the default NS of '"+example[1]+"'",
|
||||
UrlBuilder.isUriInDefaultNamespace(example[0], example[1]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
public class ObjectPropertyStatementDaoJenaTest {
|
||||
|
||||
/**
|
||||
* Test if jena lib can parse N3 that it generates.
|
||||
* owl:sameAs has been a problem when it is represetned
|
||||
* in N3 with the character =
|
||||
*/
|
||||
@Test
|
||||
public void testN3WithSameAs() {
|
||||
|
||||
String n3WithSameAs = " <http://example.com/bob> = <http://example.com/robert> .";
|
||||
|
||||
try{
|
||||
Model m = ModelFactory.createDefaultModel();
|
||||
m.read(n3WithSameAs, null, "N3");
|
||||
fail( "If this test fails it means that jena now correctly parses = when reading N3.");
|
||||
}catch(Exception ex ){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -31,6 +31,16 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
setLoggerLevel(ABoxRecomputer.class, Level.OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion1Test(){
|
||||
addABoxAssertion1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion1NoSameAsTest(){
|
||||
addABoxAssertion1(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* basic scenarios around adding abox data
|
||||
*
|
||||
|
@ -40,8 +50,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
* Add a statement c Q d and verify that d Q c
|
||||
* is inferred.
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion1() {
|
||||
public void addABoxAssertion1(boolean sameAs ) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -57,7 +66,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// create an abox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox,aBox,inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
|
||||
aBox.register( sr );
|
||||
|
||||
// add assertions to the abox and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
|
@ -68,15 +81,24 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
aBox.add(a,P,b);
|
||||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
aBox.add(c,Q,d);
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
Assert.assertTrue(inf.contains(d,P,c));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion2Test() {
|
||||
addABoxAssertion2(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion2NoSameAsTest() {
|
||||
addABoxAssertion2(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* don't infer statements already in the abox
|
||||
* (never infer because it's in the abox already)
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion2() {
|
||||
public void addABoxAssertion2(boolean sameAs ) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -107,12 +129,20 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion3Test() {
|
||||
addABoxAssertion3(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxAssertion3NoSameAsTest(){
|
||||
addABoxAssertion3(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* don't infer statements already in the abox
|
||||
* (remove the inference when it is asserted)
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion3() {
|
||||
public void addABoxAssertion3(boolean sameAs) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -127,7 +157,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// create abox and register SimpleReasoner
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
|
||||
aBox.register( sr );
|
||||
|
||||
// add statements to the abox and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
|
@ -138,13 +172,21 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
aBox.add(b,Q,a); // this should cause the inference to be removed
|
||||
Assert.assertFalse(inf.contains(b,Q,a));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addABoxAssertion4Test() {
|
||||
addABoxAssertion4(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxAssertion4NoSameAsTest() {
|
||||
addABoxAssertion4(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* adding abox data where the property has an inverse and
|
||||
* and equivalent property.
|
||||
*/
|
||||
@Test
|
||||
public void addABoxAssertion4() {
|
||||
public void addABoxAssertion4( boolean sameAs ) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -163,7 +205,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// create an ABox and register the SimpleReasoner with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add abox statements and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
|
@ -179,13 +224,22 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Assert.assertTrue(inf.contains(d,R,c));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion1Test(){
|
||||
removedABoxAssertion1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion1NoSameAsTest(){
|
||||
removedABoxAssertion1(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* basic scenarios around removing abox data
|
||||
* don't remove an inference if it's still
|
||||
* entailed by something else in the abox.
|
||||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion1() {
|
||||
public void removedABoxAssertion1(boolean sameAs) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -203,7 +257,9 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// create an ABox and register the SimpleReasoner with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add statements to the abox and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
|
@ -226,12 +282,21 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Assert.assertTrue(inf.contains(d,P,c)); // still inferred from c T d
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion2Test(){
|
||||
removedABoxAssertion2(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion2NoSameAsTest(){
|
||||
removedABoxAssertion2(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* removing abox data with equivalent and inverse properties
|
||||
* don't remove inference if it's still inferred.
|
||||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion2() {
|
||||
public void removedABoxAssertion2(boolean sameAs) {
|
||||
|
||||
// set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -253,7 +318,9 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// create an abox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add abox data and verify inferences
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
|
@ -270,11 +337,20 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
Assert.assertTrue(inf.contains(b,Q,a));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion3Test(){
|
||||
removedABoxAssertion3(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedABoxAssertion3NoSameAsTest(){
|
||||
removedABoxAssertion3(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* removing abox data with equivalent and inverse properties
|
||||
*/
|
||||
@Test
|
||||
public void removedABoxAssertion3() {
|
||||
public void removedABoxAssertion3(boolean sameAs) {
|
||||
|
||||
//set up the tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -297,7 +373,9 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
aBox.add(a,P,b);
|
||||
|
||||
// register the SimpleReasoner
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( sameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add abox statements and verify inferences
|
||||
aBox.add(b,Q,a);
|
||||
|
@ -309,11 +387,20 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
// when it's removed from the abox
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTBoxInverseAssertion1Test() throws InterruptedException {
|
||||
addTBoxInverseAssertion1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTBoxInverseAssertion1NoSameAsTest() throws InterruptedException {
|
||||
addTBoxInverseAssertion1(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* adding an inverseOf assertion to the tbox
|
||||
*/
|
||||
@Test
|
||||
public void addTBoxInverseAssertion1() throws InterruptedException {
|
||||
public void addTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
|
||||
|
||||
// Set up the TBox.
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -330,7 +417,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// set up SimpleReasoner and register it with abox. register
|
||||
// SimpleReasonerTBoxListener with the tbox.
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf );
|
||||
simpleReasoner.setSameAsEnabled( sameAs );
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -361,12 +449,21 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void removeTBoxInverseAssertion1Test() throws InterruptedException {
|
||||
removeTBoxInverseAssertion1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeTBoxInverseAssertion1NoSameAsTest() throws InterruptedException {
|
||||
removeTBoxInverseAssertion1(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* removing an inverseOf assertion from the tbox
|
||||
*/
|
||||
@Test
|
||||
public void removeTBoxInverseAssertion1() throws InterruptedException {
|
||||
public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException {
|
||||
|
||||
// set up the tbox.
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -385,7 +482,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
|
||||
// set up SimpleReasoner and SimpleReasonerTBox listener,
|
||||
// register them with abox and tbox
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
simpleReasoner.setSameAsEnabled( sameAs );
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -411,11 +509,20 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recomputeABox1Test() throws InterruptedException {
|
||||
recomputeABox1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recomputeABox1NoSameAsTest() throws InterruptedException {
|
||||
recomputeABox1(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Basic scenario around recomputing the ABox inferences
|
||||
*/
|
||||
@Test
|
||||
public void recomputeABox1() throws InterruptedException {
|
||||
public void recomputeABox1(boolean sameAs) throws InterruptedException {
|
||||
|
||||
// set up tbox
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
@ -437,6 +544,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
simpleReasoner.setSameAsEnabled( sameAs );
|
||||
aBox.register(simpleReasoner);
|
||||
|
||||
// abox statements
|
||||
|
@ -487,4 +595,4 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
|||
ontModel.writeAll(System.out,"N3",null);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,37 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
Assert.assertFalse(aBox.contains(b,S,literal1));
|
||||
Assert.assertFalse(aBox.contains(a,Q,d));
|
||||
Assert.assertFalse(aBox.contains(a,T,literal2));
|
||||
|
||||
//run same test with sameAs = false
|
||||
inf = ModelFactory.createDefaultModel();
|
||||
aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
SimpleReasoner sres = new SimpleReasoner(tBox,aBox,inf);
|
||||
sres.setSameAsEnabled( false );
|
||||
aBox.register(sres);
|
||||
|
||||
a = aBox.createResource("http://test.vivo/a");
|
||||
b = aBox.createResource("http://test.vivo/b");
|
||||
c = aBox.createResource("http://test.vivo/c");
|
||||
d = aBox.createResource("http://test.vivo/d");
|
||||
|
||||
aBox.add(a,P,c);
|
||||
aBox.add(a,S,literal1);
|
||||
aBox.add(b,Q,d);
|
||||
aBox.add(b,T,literal2);
|
||||
aBox.add(a,OWL.sameAs,b);
|
||||
|
||||
//these are now false since sameAs is off
|
||||
Assert.assertFalse(inf.contains(b,OWL.sameAs,a));
|
||||
Assert.assertFalse(inf.contains(b,P,c));
|
||||
Assert.assertFalse(inf.contains(b,S,literal1));
|
||||
Assert.assertFalse(inf.contains(a,Q,d));
|
||||
Assert.assertFalse(inf.contains(a,T,literal2));
|
||||
//these still shouldn't be in the abox
|
||||
Assert.assertFalse(aBox.contains(b,OWL.sameAs,a));
|
||||
Assert.assertFalse(aBox.contains(b,P,c));
|
||||
Assert.assertFalse(aBox.contains(b,S,literal1));
|
||||
Assert.assertFalse(aBox.contains(a,Q,d));
|
||||
Assert.assertFalse(aBox.contains(a,T,literal2));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -246,7 +277,93 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
Assert.assertFalse(inf.contains(f,Q,d));
|
||||
Assert.assertFalse(inf.contains(f,T,literal2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test of enableSameAs( false )
|
||||
*/
|
||||
@Test
|
||||
public void disabledSameAs() {
|
||||
|
||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||
|
||||
OntProperty P = tBox.createObjectProperty("http://test.vivo/P");
|
||||
P.setLabel("property P", "en-US");
|
||||
|
||||
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
|
||||
Q.setLabel("property Q", "en-US");
|
||||
|
||||
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
|
||||
S.setLabel("property S", "en-US");
|
||||
|
||||
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
|
||||
T.setLabel("property T", "en-US");
|
||||
|
||||
Literal literal1 = tBox.createLiteral("Literal value 1");
|
||||
Literal literal2 = tBox.createLiteral("Literal value 2");
|
||||
|
||||
// this is the model to receive inferences
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
|
||||
// Individuals a, b, c and d
|
||||
Resource a = aBox.createResource("http://test.vivo/a");
|
||||
Resource b = aBox.createResource("http://test.vivo/b");
|
||||
Resource c = aBox.createResource("http://test.vivo/c");
|
||||
Resource d = aBox.createResource("http://test.vivo/d");
|
||||
|
||||
aBox.add(a,P,c);
|
||||
aBox.add(a,S,literal1);
|
||||
aBox.add(b,Q,d);
|
||||
aBox.add(b,T,literal2);
|
||||
aBox.add(a,OWL.sameAs,b);
|
||||
|
||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||
Assert.assertTrue(inf.contains(b,P,c));
|
||||
Assert.assertTrue(inf.contains(b,S,literal1));
|
||||
Assert.assertTrue(inf.contains(a,Q,d));
|
||||
Assert.assertTrue(inf.contains(a,T,literal2));
|
||||
|
||||
Assert.assertFalse(aBox.contains(b,OWL.sameAs,a));
|
||||
Assert.assertFalse(aBox.contains(b,P,c));
|
||||
Assert.assertFalse(aBox.contains(b,S,literal1));
|
||||
Assert.assertFalse(aBox.contains(a,Q,d));
|
||||
Assert.assertFalse(aBox.contains(a,T,literal2));
|
||||
|
||||
//run same test with sameAs = false
|
||||
inf = ModelFactory.createDefaultModel();
|
||||
aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
SimpleReasoner sres = new SimpleReasoner(tBox,aBox,inf);
|
||||
sres.setSameAsEnabled( false );
|
||||
aBox.register(sres);
|
||||
|
||||
a = aBox.createResource("http://test.vivo/a");
|
||||
b = aBox.createResource("http://test.vivo/b");
|
||||
c = aBox.createResource("http://test.vivo/c");
|
||||
d = aBox.createResource("http://test.vivo/d");
|
||||
|
||||
aBox.add(a,P,c);
|
||||
aBox.add(a,S,literal1);
|
||||
aBox.add(b,Q,d);
|
||||
aBox.add(b,T,literal2);
|
||||
aBox.add(a,OWL.sameAs,b);
|
||||
|
||||
//these are now false since sameAs is off
|
||||
Assert.assertFalse(inf.contains(b,OWL.sameAs,a));
|
||||
Assert.assertFalse(inf.contains(b,P,c));
|
||||
Assert.assertFalse(inf.contains(b,S,literal1));
|
||||
Assert.assertFalse(inf.contains(a,Q,d));
|
||||
Assert.assertFalse(inf.contains(a,T,literal2));
|
||||
//these still shouldn't be in the abox
|
||||
Assert.assertFalse(aBox.contains(b,OWL.sameAs,a));
|
||||
Assert.assertFalse(aBox.contains(b,P,c));
|
||||
Assert.assertFalse(aBox.contains(b,S,literal1));
|
||||
Assert.assertFalse(aBox.contains(a,Q,d));
|
||||
Assert.assertFalse(aBox.contains(a,T,literal2));
|
||||
}
|
||||
|
||||
/*
|
||||
* sameAs with datatype properties
|
||||
*/
|
||||
|
@ -723,4 +840,4 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
|||
ontModel.writeAll(System.out,"N3",null);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.reasoner;
|
||||
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
||||
|
||||
|
@ -38,12 +38,20 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
setLoggerLevel(SimpleReasonerTBoxListener.class, Level.OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion1Test(){
|
||||
addABoxTypeAssertion1(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion1NoSameAsTest(){
|
||||
addABoxTypeAssertion1(false);
|
||||
}
|
||||
/*
|
||||
* Test that when an individual is asserted to be of a type,
|
||||
* its asserted type is not added to the inference graph
|
||||
*/
|
||||
@Test
|
||||
public void addABoxTypeAssertion1(){
|
||||
public void addABoxTypeAssertion1( boolean sameAsEnabled ){
|
||||
|
||||
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -62,7 +70,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
// create an ABox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
simpleReasoner.setSameAsEnabled( sameAsEnabled );
|
||||
aBox.register(simpleReasoner);
|
||||
|
||||
// Individual x
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
|
@ -75,13 +85,20 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
Assert.assertFalse(inf.contains(xisb));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion2Test(){
|
||||
addABoxTypeAssertion2(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxTypeAssertion2NoSameAs(){
|
||||
addABoxTypeAssertion2(false);
|
||||
}
|
||||
/*
|
||||
* Test that when an individual is asserted have a type,
|
||||
* that inferences are materialized that it has the types
|
||||
* of its superclasses
|
||||
*/
|
||||
@Test
|
||||
public void addABoxTypeAssertion2(){
|
||||
public void addABoxTypeAssertion2(boolean enableSameAs){
|
||||
|
||||
// Create a Tbox with a simple class hierarchy. D and E are subclasses
|
||||
// of C. B and C are subclasses of A. Pellet will compute TBox inferences.
|
||||
|
@ -113,7 +130,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
// create an Abox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add a statement to the ABox that individual x is of type E.
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
|
@ -128,11 +147,18 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
Assert.assertTrue(inf.contains(xisa));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion3Test() throws InterruptedException{
|
||||
addABoxTypeAssertion3(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxTypeAssertion3NoSameAs() throws InterruptedException{
|
||||
addABoxTypeAssertion3(false);
|
||||
}
|
||||
/*
|
||||
* Test inference based on class equivalence
|
||||
*/
|
||||
@Test
|
||||
public void addABoxTypeAssertion3() throws InterruptedException {
|
||||
public void addABoxTypeAssertion3(boolean enableSameAs) throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
|
@ -142,7 +168,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -182,11 +210,18 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion4Test()throws InterruptedException{
|
||||
addABoxTypeAssertion4(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxTypeAssertion4NoSameAs()throws InterruptedException{
|
||||
addABoxTypeAssertion4(false);
|
||||
}
|
||||
/*
|
||||
* Test inference based on class equivalence
|
||||
*/
|
||||
@Test
|
||||
public void addABoxTypeAssertion4() throws InterruptedException {
|
||||
public void addABoxTypeAssertion4(boolean enableSameAs) throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
|
@ -196,7 +231,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -228,11 +265,18 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addABoxTypeAssertion5Test()throws InterruptedException{
|
||||
addABoxTypeAssertion5(true);
|
||||
}
|
||||
@Test
|
||||
public void addABoxTypeAssertion5NoSameAs()throws InterruptedException{
|
||||
addABoxTypeAssertion5(false);
|
||||
}
|
||||
/*
|
||||
* Test inference based on class equivalence
|
||||
*/
|
||||
@Test
|
||||
public void addABoxTypeAssertion5() throws InterruptedException {
|
||||
public void addABoxTypeAssertion5(boolean enableSameAs) throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
|
@ -242,7 +286,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -279,6 +325,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeABoxTypeAssertion1Test()throws InterruptedException{
|
||||
removeABoxTypeAssertion1(true);
|
||||
}
|
||||
@Test
|
||||
public void removeABoxTypeAssertion1NoSameAs()throws InterruptedException{
|
||||
removeABoxTypeAssertion1(false);
|
||||
}
|
||||
/*
|
||||
* Test that when it is retracted that an individual is of a type,
|
||||
* that the inferences that it is of the type of all superclasses
|
||||
|
@ -287,8 +341,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* TBox, ABox and inference graph minus the retracted type statement)
|
||||
* should not be retracted.
|
||||
*/
|
||||
@Test
|
||||
public void removeABoxTypeAssertion1(){
|
||||
public void removeABoxTypeAssertion1(boolean enableSameAs){
|
||||
|
||||
// Create a Tbox with a simple class hierarchy. C is a subclass of B
|
||||
// and B is a subclass of A. Pellet will compute TBox inferences.
|
||||
|
@ -312,7 +365,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
// create an Abox and register the SimpleReasoner listener with it
|
||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
aBox.register( sr );
|
||||
|
||||
// add a statement to the ABox that individual x is of type C.
|
||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
||||
|
@ -335,6 +390,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion1Test()throws InterruptedException{
|
||||
addTBoxSubClassAssertion1(true);
|
||||
}
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion1NoSameAs()throws InterruptedException{
|
||||
addTBoxSubClassAssertion1(false);
|
||||
}
|
||||
/*
|
||||
* Test the addition of a subClassOf statement to
|
||||
* the TBox. The instance data that is the basis
|
||||
|
@ -351,8 +414,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* rdfs:subClassOf statement, this test serves
|
||||
* as a test of equivalentClass statements also.
|
||||
*/
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion1() throws InterruptedException {
|
||||
public void addTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
|
@ -362,7 +424,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -408,6 +472,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion2Test()throws InterruptedException{
|
||||
addTBoxSubClassAssertion2(true);
|
||||
}
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion2NoSameAs()throws InterruptedException{
|
||||
addTBoxSubClassAssertion2(false);
|
||||
}
|
||||
/*
|
||||
* Test the addition of a subClassOf statement to
|
||||
* the TBox. The instance data that is the basis
|
||||
|
@ -424,8 +496,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* as some test of equivalentClass statements also.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void addTBoxSubClassAssertion2() throws InterruptedException {
|
||||
public void addTBoxSubClassAssertion2(boolean enableSameAs) throws InterruptedException {
|
||||
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
|
@ -435,7 +506,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -480,6 +553,14 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void removeTBoxSubClassAssertion1Test()throws InterruptedException{
|
||||
removeTBoxSubClassAssertion1(true);
|
||||
}
|
||||
@Test
|
||||
public void removeTBoxSubClassAssertion1NoSameAs()throws InterruptedException{
|
||||
removeTBoxSubClassAssertion1(false);
|
||||
}
|
||||
/*
|
||||
* Test the removal of a subClassOf statement from
|
||||
* the TBox. The instance data that is the basis
|
||||
|
@ -487,8 +568,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* inference graph.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void removeTBoxSubClassAssertion1() throws InterruptedException {
|
||||
public void removeTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -497,7 +577,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -582,6 +664,17 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
@Ignore(" needs PelletListener infrastructure which is not in this suite.")
|
||||
@Test
|
||||
public void bcdTest()throws InterruptedException{
|
||||
bcd(true);
|
||||
}
|
||||
|
||||
@Ignore(" needs PelletListener infrastructure which is not in this suite.")
|
||||
@Test
|
||||
public void bcdNoSameAsTest()throws InterruptedException{
|
||||
bcd(false);
|
||||
}
|
||||
/*
|
||||
* Test the removal of a subClassOf statement from
|
||||
* the TBox. The instance data that is the basis
|
||||
|
@ -589,12 +682,12 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
* inference graph.
|
||||
*
|
||||
*/
|
||||
//@Test - this test would need PelletListener infrastructure, which we're not
|
||||
// this test would need PelletListener infrastructure, which we're not
|
||||
// testing in this suite. The reason it doesn't work as it is because
|
||||
// the SimpleReasonerTBoxListener is not listening to the tBox inference
|
||||
// model as Pellet is updating it. I could simulate it by adding to the
|
||||
// tBox assertions what we can count on Pellet to infer.
|
||||
public void bcdTest() throws InterruptedException {
|
||||
public void bcd(boolean enableSameAs) throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -604,6 +697,7 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
simpleReasoner.setSameAsEnabled( enableSameAs );
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -654,12 +748,19 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mstTest1Test()throws InterruptedException{
|
||||
mstTest1(true);
|
||||
}
|
||||
@Test
|
||||
public void mstTest1NoSameAs()throws InterruptedException{
|
||||
mstTest1(false);
|
||||
}
|
||||
/*
|
||||
* Test computation of mostSpecificType annotations in response
|
||||
* to an added/removed ABox type assertion.
|
||||
*/
|
||||
@Test
|
||||
public void mstTest1() throws InterruptedException {
|
||||
public void mstTest1(boolean enableSameAs) throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -668,7 +769,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -732,12 +835,19 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void mstTest2Test()throws InterruptedException{
|
||||
mstTest2(true);
|
||||
}
|
||||
@Test
|
||||
public void mstTest2NoSameAs()throws InterruptedException{
|
||||
mstTest2(false);
|
||||
}
|
||||
/*
|
||||
* Test computation of mostSpecificType annotations in response
|
||||
* to an added ABox type assertion.
|
||||
*/
|
||||
@Test
|
||||
public void mstTest2() throws InterruptedException {
|
||||
public void mstTest2(boolean enableSameAs) throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -746,7 +856,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -785,13 +897,20 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
|
||||
simpleReasonerTBoxListener.setStopRequested();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void mstTest3Test()throws InterruptedException{
|
||||
mstTest3(true);
|
||||
}
|
||||
@Test
|
||||
public void mstTest3NoSameAs()throws InterruptedException{
|
||||
mstTest3(false);
|
||||
}
|
||||
/*
|
||||
* Test computation of mostSpecificType annotations in response
|
||||
* to an added/removed TBox assertions.
|
||||
*/
|
||||
@Test
|
||||
public void mstTest3() throws InterruptedException {
|
||||
public void mstTest3(boolean enableSameAs) throws InterruptedException {
|
||||
// Create TBox, ABox and Inference models and register
|
||||
// the ABox reasoner listeners with the ABox and TBox
|
||||
// Pellet will compute TBox inferences
|
||||
|
@ -800,7 +919,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
Model inf = ModelFactory.createDefaultModel();
|
||||
|
||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||
SimpleReasoner sr = new SimpleReasoner(tBox, aBox, inf);
|
||||
sr.setSameAsEnabled( enableSameAs );
|
||||
SimpleReasoner simpleReasoner = sr ;
|
||||
aBox.register(simpleReasoner);
|
||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||
tBox.register(simpleReasonerTBoxListener);
|
||||
|
@ -906,4 +1027,4 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
|||
ontModel.writeAll(System.out,"N3",null);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue