diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java index 62572b4ae..52efc0570 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/SolrQueryTest.java @@ -26,6 +26,7 @@ import org.apache.solr.common.SolrInputDocument; import org.apache.solr.core.CoreContainer; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.xml.sax.SAXException; @@ -60,6 +61,9 @@ import edu.cornell.mannlib.vitro.webapp.search.solr.documentBuilding.IndividualT * All RDF/XML files in webapp/test/testontologies/SolrQueryTestRDF will be * loaded into the model. */ + +//ignored for now since the solr directory isn't yet found when running from vivo. +@Ignore public class SolrQueryTest extends AbstractTestClass { /** Key of system property for build directory. */ final static String buildDirSystemPropertyKey = "vitro.build.dir"; @@ -151,13 +155,23 @@ public class SolrQueryTest extends AbstractTestClass { assertTrue("no test RDF files found", files.length > 0 ); OntModel model = ModelFactory.createOntologyModel(); - for (File file : files ){ + for (File file : files ){ InputStream in = FileManager.get().open( file.getAbsolutePath() ); - assertNotNull("Could not load file " + file.getAbsolutePath(), in ); + assertNotNull("Could not load file " + file.getAbsolutePath(), in ); try{ - model.read(in,null); + if( file.getName().endsWith(".rdf") ){ + model.read(in,null); + }else if( file.getName().endsWith(".n3")){ + model.read(in,null,"N3"); + }else if( file.getName().endsWith(".nt")){ + model.read(in,null,"N-TRIPLE"); + }else if( file.getName().endsWith(".ttl")){ + model.read(in,null,"TURTLE"); + }else{ + throw new Exception("Format unknown for file name " + file.getName()); + } }catch(Throwable th){ - throw new Exception( "Could not load RDF/XML file " + throw new Exception( "Could not load RDF file " + file.getAbsolutePath() , th); } } @@ -255,6 +269,36 @@ public class SolrQueryTest extends AbstractTestClass { return uris; } + /** + * Test that a document with the given URIs are in the results for the query. + * @throws SolrServerException */ + void testQueryGetsDocs(String errmsg, SolrQuery query, String[] expectedUris) throws SolrServerException{ + assertNotNull(errmsg + " but query was null", query); + assertNotNull(errmsg + " but expected URIs was null", expectedUris ); + + QueryResponse resp = solr.query(query); + if( resp == null ) + fail( errmsg + " but Could not get a solr response"); + + Set uris = new HashSet(Arrays.asList( expectedUris )); + for( SolrDocument doc : resp.getResults()){ + assertNotNull(errmsg + ": solr doc was null", doc); + String uri = (String) doc.getFirstValue( VitroSearchTermNames.URI ); + assertNotNull(errmsg+": no URI field in solr doc" , uri); + uris.remove( uri ); + } + if( uris.size() > 0){ + String errorMsg = + "\nThe query '"+ query + "' was expected " + + "to return the following URIs but did not:"; + for( String uri : uris){ + errorMsg= errorMsg+"\n" + uri; + } + + fail( errmsg + errorMsg); + } + } + @Test public void testSolrWasStarted() throws SolrServerException, IOException { assertNotNull( solr ); @@ -270,36 +314,13 @@ public class SolrQueryTest extends AbstractTestClass { testQueryGetsDocs("Expect to find a doc when searching for 'corson'", query,new String[]{ "http://vivo.cornell.edu/individual/individual22972" } ) ; } + + @Test + public void testFormFeed() throws SolrServerException{ + /* make sure that we have the document in the index before we do anything */ + SolrQuery query = new SolrQuery().setQuery("vivo15"); - - - /** - * Test that a document with the given URIs are in the results for the query. - * @throws SolrServerException */ - void testQueryGetsDocs(String errmsg, SolrQuery query, String[] expectedUris) throws SolrServerException{ - assertNotNull(errmsg + " but query was null", query); - assertNotNull(errmsg + " but expected URIs was null", expectedUris ); - - QueryResponse resp = solr.query(query); - if( resp == null ) - fail( errmsg + " but Could not get a solr response"); - - Set uris = new HashSet(Arrays.asList( expectedUris )); - for( SolrDocument doc : resp.getResults()){ - assertNotNull(errmsg + ": solr doc was null", doc); - String uri = (String) doc.getFirstValue( VitroSearchTermNames.URI ); - assertNotNull(errmsg+": no URI field in solr doc" , uri); - uris.remove( uri ); - } - if( uris.size() > 0){ - String errorMsg = - "\nThe query '"+ query + "' was expected " + - "to return the following URIs but did not:"; - for( String uri : uris){ - errorMsg= errorMsg+"\n" + uri; - } - - fail( errmsg + errorMsg); - } + testQueryGetsDocs("Expect to find a doc when searching for 'vivo15'", + query,new String[]{ "http://vivo.cornell.edu/individual/individualIssueVivo15" } ) ; } } diff --git a/webapp/test/testontologies/SolrQueryTestRDF/vivo15.2.n3 b/webapp/test/testontologies/SolrQueryTestRDF/vivo15.2.n3 new file mode 100644 index 000000000..20fc4891e --- /dev/null +++ b/webapp/test/testontologies/SolrQueryTestRDF/vivo15.2.n3 @@ -0,0 +1,45 @@ +@prefix sce: . +@prefix dcterms: . +@prefix local: . +@prefix skos: . +@prefix foaf: . +@prefix pubmed: . +@prefix vitro-public: . +@prefix bibo: . +@prefix owl: . +@prefix hr: . +@prefix cce: . +@prefix vivo: . +@prefix aktp: . +@prefix scires: . +@prefix dcelem: . +@prefix vivoc: . +@prefix stars: . +@prefix far: . +@prefix pvs: . +@prefix acti: . +@prefix mann: . +@prefix event: . +@prefix aka: . +@prefix geo: . +@prefix ero: . +@prefix fabio: . +@prefix rdfsyn: . +@prefix socsci: . +@prefix j.0: . +@prefix rdfs: . +@prefix ospcu: . +@prefix c4o: . +@prefix vitro: . + + vivo:overview "There is a form feed in the following text. Hex 0c, that sometimes displays as ^L. Star Award for excellence in scientic publication and for productive collaborations with other Center scientists, U.S. Department of the Interior, 2009. Publications Award for scientist at Florida Integrated Science Center with highest annual scien-tic productivity as measured by number, quality, and impact of publications., U.S. Department of the Interior, 2009."; + vivo:webpage ; + a mann:CornellNonAcademicStaff, + local:InternalThing, + vivoc:CornellAffiliatedPerson, + vivoc:CornellEmployee, + vivo:NonAcademic, + owl:Thing, + foaf:Agent, + foaf:Person; + rdfs:label "Test individual for issue vivo15". \ No newline at end of file diff --git a/webapp/test/testontologies/SolrQueryTestRDF/vivo15.n3 b/webapp/test/testontologies/SolrQueryTestRDF/vivo15.n3 new file mode 100644 index 000000000..4b961e6ad --- /dev/null +++ b/webapp/test/testontologies/SolrQueryTestRDF/vivo15.n3 @@ -0,0 +1,45 @@ +@prefix sce: . +@prefix dcterms: . +@prefix local: . +@prefix skos: . +@prefix foaf: . +@prefix pubmed: . +@prefix vitro-public: . +@prefix bibo: . +@prefix owl: . +@prefix hr: . +@prefix cce: . +@prefix vivo: . +@prefix aktp: . +@prefix scires: . +@prefix dcelem: . +@prefix vivoc: . +@prefix stars: . +@prefix far: . +@prefix pvs: . +@prefix acti: . +@prefix mann: . +@prefix event: . +@prefix aka: . +@prefix geo: . +@prefix ero: . +@prefix fabio: . +@prefix rdfsyn: . +@prefix socsci: . +@prefix j.0: . +@prefix rdfs: . +@prefix ospcu: . +@prefix c4o: . +@prefix vitro: . + + vivo:overview "There is a form feed in the following text. Hex 0c, that sometimes displays as ^L. Star Award for excellence in scienti c publication and for productive collaborations with other Center scientists, U.S. Department of the Interior, 2009. Publications Award for scientist at Florida Integrated Science Center with highest annual scien-ti c productivity as measured by number, quality, and impact of publications., U.S. Department of the Interior, 2009."; + vivo:webpage ; + a mann:CornellNonAcademicStaff, + local:InternalThing, + vivoc:CornellAffiliatedPerson, + vivoc:CornellEmployee, + vivo:NonAcademic, + owl:Thing, + foaf:Agent, + foaf:Person; + rdfs:label "Test individual for issue vivo15". \ No newline at end of file