From 9d568a3a574a559d8f7f61982fc07fd51d6fd50f Mon Sep 17 00:00:00 2001 From: deepakkoni Date: Fri, 15 Jul 2011 15:41:07 +0000 Subject: [PATCH] committing test cases for Presenter Role (Presentation, Invited Talk) and Researcher Role (Grant, Project) --- .../AdditionalURIsForContextNodes.java | 21 +- .../AdditionalURIsForContextNodesTest.java | 198 ++++++++++++++++++ 2 files changed, 212 insertions(+), 7 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java index 51e197ca3..43b545653 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodes.java @@ -453,7 +453,7 @@ public class AdditionalURIsForContextNodes implements AdditionalURIsToIndex { // core:PresenterRole -- core:presenterRoleOf - // If the person changes, update the presenter role in organization + // If the person changes, update the presentation multiValuedQueriesForRole.add(prefix + "SELECT (str(?d) as ?organization) \n" + "WHERE {\n" @@ -462,18 +462,18 @@ public class AdditionalURIsForContextNodes implements AdditionalURIsToIndex { + " ?c rdf:type core:PresenterRole ; core:roleIn ?d .\n" + " }"); - // If the organization changes, update the presenter role of person + // If the presentation changes, update the person multiValuedQueriesForRole.add(prefix + "SELECT (str(?d) as ?person) \n" + "WHERE {\n" - + "?uri rdf:type foaf:Organization ; ?b ?c . \n" + + "?uri rdf:type core:Presentation ; ?b ?c . \n" + " ?c rdf:type core:PresenterRole ; core:presenterRoleOf ?d .\n" + " }"); // core:ResearcherRole -- core:researcherRoleOf - // If the person changes, update the researcher role in organization + // If the person changes, update the grant multiValuedQueriesForRole.add(prefix + "SELECT (str(?d) as ?organization) \n" + "WHERE {\n" @@ -482,16 +482,23 @@ public class AdditionalURIsForContextNodes implements AdditionalURIsToIndex { + " ?c rdf:type core:ResearcherRole ; core:roleIn ?d .\n" + " }"); - // If the organization changes, update the researcher role of person + // If the grant changes, update the person multiValuedQueriesForRole.add(prefix + "SELECT (str(?d) as ?person) \n" + "WHERE {\n" - + "?uri rdf:type foaf:Organization ; ?b ?c . \n" + + "?uri rdf:type core:Grant ; ?b ?c . \n" + " ?c rdf:type core:ResearcherRole ; core:researcherRoleOf ?d .\n" + " }"); - + // If the project changes, update the person + multiValuedQueriesForRole.add(prefix + + "SELECT (str(?d) as ?person) \n" + + "WHERE {\n" + + + "?uri rdf:type core:Project ; ?b ?c . \n" + + " ?c rdf:type core:ResearcherRole ; core:researcherRoleOf ?d .\n" + + " }"); // core:EditorRole -- core:editorRoleOf, core:forInformationResource (person, informationresource) diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodesTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodesTest.java index be2be148e..47369c4ce 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodesTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/indexing/AdditionalURIsForContextNodesTest.java @@ -318,5 +318,203 @@ public class AdditionalURIsForContextNodesTest { } + + @Test + public void testPresenterRoleChangesForPresentation(){ + String n3 = + " . \n" + + " \"5, Test\" . \n" + + " \"5\"^^ . \n" + + " \"Test\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + + " . \n" + + " \"Presenter Role\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + + " \"Presentation 1\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" ; + + + //make a test model with an person, a presenter role node and a presentation + OntModel model = ModelFactory.createOntologyModel(); + model.read( new StringReader(n3), null, "N3"); + + //make an AdditionalURIsForContextNodesTest object with that model + AdditionalURIsForContextNodes uriFinder = new AdditionalURIsForContextNodes( model ); + + //if the person changes then the presentation needs to be updated + List uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n5596"); + assertTrue("did not find service for clinical role", uris.contains("http://vivo.scripps.edu/individual/n1305" )); + + //if the presentation changes then the person needs to be updated + uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n1305"); + assertTrue("did not find person for clinical role", uris.contains("http://vivo.scripps.edu/individual/n5596" )); + } + + + @Test + public void testPresenterRoleChangesForInvitedTalk(){ + String n3 = + + " . \n " + + " \"6, Test\" . \n " + + " \"6\"^^ . \n " + + " \"Test\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + + " . \n " + + " \"Presenter Role 2\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + + " \"Invited Talk 1\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " ; + + //make a test model with an person, a presenter role node and an invited talk + OntModel model = ModelFactory.createOntologyModel(); + model.read( new StringReader(n3), null, "N3"); + + //make an AdditionalURIsForContextNodesTest object with that model + AdditionalURIsForContextNodes uriFinder = new AdditionalURIsForContextNodes( model ); + + //if the person changes then the invited talk needs to be updated + List uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n4112"); + assertTrue("did not find service for clinical role", uris.contains("http://vivo.scripps.edu/individual/n4107" )); + + //if the invited talk changes then the person needs to be updated + uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n4107"); + assertTrue("did not find person for clinical role", uris.contains("http://vivo.scripps.edu/individual/n4112" )); + + } + + + @Test + public void testResearcherRoleForGrant(){ + + String n3 = + + " \"7, Test\" . \n" + + " \"7\"^^ . \n" + + " \"Test\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + + " \"Researcher Role\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + + " \"Grant1\"^^ . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" + + " . \n" ; + + + //make a test model with an person, a researcher role node and a grant + OntModel model = ModelFactory.createOntologyModel(); + model.read( new StringReader(n3), null, "N3"); + + //make an AdditionalURIsForContextNodesTest object with that model + AdditionalURIsForContextNodes uriFinder = new AdditionalURIsForContextNodes( model ); + + //if the person changes then the grant needs to be updated + List uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n4957"); + assertTrue("did not find service for clinical role", uris.contains("http://vivo.scripps.edu/individual/n4252" )); + + //if the grant changes then the person needs to be updated + uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n4252"); + assertTrue("did not find person for clinical role", uris.contains("http://vivo.scripps.edu/individual/n4957" )); + + + } + + @Test + public void testResearcherRoleForProject(){ + + String n3 = + + " \"8, Test\" . \n " + + " \"8\"^^ . \n " + + " \"Test\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + + " \"Researcher Role 2\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + + + " \"Project2\"^^ . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " + + " . \n " ; + + + + //make a test model with an person, a researcher role node and a project + OntModel model = ModelFactory.createOntologyModel(); + model.read( new StringReader(n3), null, "N3"); + + //make an AdditionalURIsForContextNodesTest object with that model + AdditionalURIsForContextNodes uriFinder = new AdditionalURIsForContextNodes( model ); + + //if the person changes then the project needs to be updated + List uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n2029"); + assertTrue("did not find service for clinical role", uris.contains("http://vivo.scripps.edu/individual/n564" )); + + //if the project changes then the person needs to be updated + uris = uriFinder.findAdditionalURIsToIndex( "http://vivo.scripps.edu/individual/n564"); + assertTrue("did not find person for clinical role", uris.contains("http://vivo.scripps.edu/individual/n2029" )); + + + + } + + + }