From d2b3213c7be5b9205f0424f46f995dacc20bf0ed Mon Sep 17 00:00:00 2001 From: briancaruso Date: Fri, 12 Aug 2011 17:08:05 +0000 Subject: [PATCH] Adding test for ThumbnailImageURL.java --- .../webapp/search/solr/ThumbnailImageURL.java | 11 +- .../search/solr/ThumbnailImageURLTest.java | 76 ++++ .../vitro/webapp/search/solr/testPerson.n3 | 347 ++++++++++++++++++ 3 files changed, 427 insertions(+), 7 deletions(-) create mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java create mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURL.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURL.java index a2d5076e8..c334a15ab 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURL.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURL.java @@ -46,7 +46,6 @@ public class ThumbnailImageURL implements DocumentModifier { private Model model; private Log log = LogFactory.getLog(ThumbnailImageURL.class); - private boolean shutdown = false; static VitroSearchTermNames term = new VitroSearchTermNames(); String fieldForThumbnailURL = term.THUMBNAIL_URL; @@ -65,7 +64,7 @@ public class ThumbnailImageURL implements DocumentModifier { } - private String runQueryForThumbnailLocation(Individual individual) { + protected String runQueryForThumbnailLocation(Individual individual) { StringBuffer result = new StringBuffer(); QuerySolutionMap initialBinding = new QuerySolutionMap(); @@ -91,9 +90,8 @@ public class ThumbnailImageURL implements DocumentModifier { } } } - }catch(Throwable t){ - if( ! shutdown ) - log.error(t,t); + }catch(Throwable t){ + log.error(t,t); } finally{ qExec.close(); } @@ -105,8 +103,7 @@ public class ThumbnailImageURL implements DocumentModifier { } @Override - public void shutdown() { - shutdown = true; + public void shutdown() { } } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java new file mode 100644 index 000000000..2fd814c87 --- /dev/null +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/ThumbnailImageURLTest.java @@ -0,0 +1,76 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ +/** + * + */ +package edu.cornell.mannlib.vitro.webapp.search.solr; + +import java.io.InputStream; + +import org.apache.log4j.Level; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.SolrInputField; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler; + +import edu.cornell.mannlib.vitro.testing.AbstractTestClass; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; +import edu.cornell.mannlib.vitro.webapp.dao.jena.MenuDaoJenaTest; +import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames; + +/** + * @author bdc34 + * + */ +public class ThumbnailImageURLTest extends AbstractTestClass{ + OntModel testModel; + String personsURI = "http://vivo.cornell.edu/individual/individual8803"; + + static VitroSearchTermNames term = new VitroSearchTermNames(); + String fieldForThumbnailURL = term.THUMBNAIL_URL; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF); + + Model model = ModelFactory.createDefaultModel(); + InputStream in = MenuDaoJenaTest.class.getResourceAsStream("resources/menuForTest.n3"); + model.read(in,"","N3"); + testModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model); + } + + /** + * Test method for {@link edu.cornell.mannlib.vitro.webapp.search.solr.ThumbnailImageURL#modifyDocument(edu.cornell.mannlib.vitro.webapp.beans.Individual, org.apache.solr.common.SolrInputDocument, java.lang.StringBuffer)}. + */ + @Test + public void testModifyDocument() { + SolrInputDocument doc = new SolrInputDocument(); + ThumbnailImageURL testMe = new ThumbnailImageURL( testModel ); + Individual ind = new IndividualImpl(); + ind.setURI(personsURI); + try { + testMe.modifyDocument(ind, doc, null); + } catch (SkipIndividualException e) { + Assert.fail("person was skipped: " + e.getMessage()); + } + + SolrInputField thumbnailField = doc.getField(fieldForThumbnailURL); + Assert.assertNotNull(thumbnailField); + + Assert.assertNotNull( thumbnailField.getValues() ); + Assert.assertEquals(1, thumbnailField.getValueCount()); + + Assert.assertEquals("http://vivo.cornell.edu/individual/n13658", thumbnailField.getFirstValue()); + } + +} diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 new file mode 100644 index 000000000..3a5af2edf --- /dev/null +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/search/solr/testPerson.n3 @@ -0,0 +1,347 @@ +# An example of the RDF for a person from 1.2.1 vivo.cornell.edu +# The person's URI is + + + a , , ; + + "Allen, P E" ; + + "2"^^ ; + + ; + + . + + + a , , , ; + + "THE SCIENCE KNOWLEDGE AND EDUCATION NETWORK BUILDING A USER BASE AROUND SCIENTIFIC PUBLICATIONS: EDITING ONLINE CONTENT AND ANNOTATING SCIENTIFIC MATERIALS" ; + + ; + + ; + + ; + + "46750" ; + + , , , ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" ; + + "NSF" ; + + "" ; + + "NSF EHR" . + + + a , , ; + + "Allen, P E" ; + + "3"^^ ; + + ; + + . + + + a , , , , , , ; + + "The seasonal decline in avian clutch size: Strategy or physiological constraints? " ; + + "932"^^ ; + + "922"^^ ; + + "77" ; + + ; + + ; + + , . + + + a , , ; + + "Allen, P E" ; + + "3"^^ ; + + ; + + . + + + a , , , ; + + "DIGITAL RESOURCE DISCOVERY AND DYNAMIC LEARNING COMMUNITIES FOR A CHANGING BIOLOGY" ; + + ; + + ; + + ; + + ; + + "62212" ; + + ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" ; + + "ECOLOGICAL SOCIETY OF AMERICA" ; + + "" ; + + "" . + + + a , ; + + "/file/n54945/_main_image_allen_paul_thumb.gif" . + + + a , , , ; + + "THE BIODIVERSITY ANALYSIS PIPELINE" ; + + ; + + ; + + ; + + "53811" ; + + , , ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" ; + + "NSF" ; + + "" ; + + "NSF EHR" . + + + a , , , , ; + + ; + + ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" . + + + a , , , , , , ; + + "Breeding dispersal and philopatry in the tree swallow" ; + + "776"^^ ; + + "768"^^ ; + + "106" ; + + ; + + ; + + , , , , , , , , . + + + a , , ; + + "Allen, P E" ; + + "3"^^ ; + + ; + + . + + + a , , , , , , ; + + "Effects of handicapping on female condition and reproduction in Tree Swallows (Tachycineta bicolor)" ; + + "747"^^ ; + + "737"^^ ; + + "112" ; + + ; + + ; + + , . + + + a , , , ; + + "Info Tech Area Manager II" ; + + "Info Tech Area Mgr II" ; + + ; + + . + + + a , , , ; + + "INTEROP: CREATION OF A VIRTUAL DATA CENTER FOR THE BIODIVERSITY, ECOLOGICAL AND ENVIRONMENTAL SCIENCES" ; + + ; + + ; + + ; + + ; + + "56145" ; + + , ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" ; + + "U OF NEW MEXICO" ; + + "" ; + + "" . + + + a , , , , , , ; + + "Allen, Paul Edward" ; + + ; + + , , , , ; + + , ; + + , ; + + """

Paul's background in computer science and ecology (M.S. Computer Science, Carnegie Mellon U., 1991; M.S. Organismal Biology and Ecology, U. Montana, 1998) serve him well as software architect and head of software development for the Cornell Lab of Ornithology (CLO) Information Technologies (IT) department. Since joining the CLO staff in 1997 and the IT department in 1999, Paul has focused on building software systems to collect bird monitoring information from citizen scientists. Most recently Paul has helped bring the \"Birds of North America\" into the digital age and will be building a new framework to create communities focused on scientific references such as the \"Birds of North America.\"

+ +

While work on birds has taken Paul from Panama and the Bahamas to Alaska, the most important thing to him is using his skills for conservation.

"""^^ ; + + ; + + "8287" . + + + a , , , , ; + + ; + + ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" . + + + a , , ; + + "Allen, P E" ; + + "2"^^ ; + + ; + + . + + + a , ; + + ; + + "_main_image_allen_paul_thumb.gif"^^ ; + + "image/gif"^^ ; + + . + + + a , , , , , , ; + + "The natal dispersal of tree swallows in a continuous mainland environment" ; + + "1090"^^ ; + + "1080"^^ ; + + "74" ; + + ; + + ; + + , , , , , , . + + + a , ; + + ; + + "allen_paul_thumb.gif"^^ ; + + "image/gif"^^ . + + + a , , , , ; + + ; + + ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" . + + + a , , , , ; + + ; + + ; + + "2011-06-27-04:00" ; + + "OSPWH-Harvester" . + + + a , , , , , , ; + + "Geographic differences in seasonal clutch size variation in multi-brooded bird species" ; + + "651"^^ ; + + "646"^^ ; + + "144" ; + + ; + + ; + + , , .