Author: rwesten Date: Mon Dec 6 17:28:38 2010 New Revision: 1042736 URL: http://svn.apache.org/viewvc?rev=1042736&view=rev Log: Both Unit Test do no longer fail if offline or the remote geonames.org webservice is unavailable. Note that only UnknownHostExceptions (if offline) and SocketTimeoutException (service unavailable) do no longer cause the test to fail. Other IO Exceptions are still treated as Errors.
This should resolve https://issues.apache.org/jira/browse/STANBOL-9 Modified: incubator/stanbol/trunk/fise/engines/entitytagging/ (props changed) incubator/stanbol/trunk/fise/engines/geonames/src/test/java/eu/iksproject/fise/engines/geonames/impl/TestLocationEnhancementEngine.java incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java Propchange: incubator/stanbol/trunk/fise/engines/entitytagging/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Mon Dec 6 17:28:38 2010 @@ -0,0 +1 @@ +target Modified: incubator/stanbol/trunk/fise/engines/geonames/src/test/java/eu/iksproject/fise/engines/geonames/impl/TestLocationEnhancementEngine.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/engines/geonames/src/test/java/eu/iksproject/fise/engines/geonames/impl/TestLocationEnhancementEngine.java?rev=1042736&r1=1042735&r2=1042736&view=diff ============================================================================== --- incubator/stanbol/trunk/fise/engines/geonames/src/test/java/eu/iksproject/fise/engines/geonames/impl/TestLocationEnhancementEngine.java (original) +++ incubator/stanbol/trunk/fise/engines/geonames/src/test/java/eu/iksproject/fise/engines/geonames/impl/TestLocationEnhancementEngine.java Mon Dec 6 17:28:38 2010 @@ -7,6 +7,8 @@ import static org.junit.Assert.assertTru import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.util.Date; import java.util.Dictionary; import java.util.Hashtable; @@ -20,9 +22,11 @@ import org.apache.commons.io.IOUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import eu.iksproject.fise.engines.geonames.impl.MockComponentContext; import eu.iksproject.fise.servicesapi.ContentItem; +import eu.iksproject.fise.servicesapi.EngineException; import eu.iksproject.fise.servicesapi.TextAnnotation; import eu.iksproject.fise.servicesapi.helper.RdfEntityFactory; import eu.iksproject.fise.servicesapi.rdf.OntologicalClasses; @@ -31,6 +35,7 @@ import eu.iksproject.fise.servicesapi.rd public class TestLocationEnhancementEngine { + private Logger log = LoggerFactory.getLogger(TestLocationEnhancementEngine.class); /** * The context for the tests (same as in TestOpenNLPEnhancementEngine) */ @@ -110,7 +115,7 @@ public class TestLocationEnhancementEngi testAnnotation.setEnd(start+name.length()); } @Test - public void testLocationEnhancementEngine() throws Exception{ + public void testLocationEnhancementEngine() {//throws Exception{ //create a content item ContentItem ci = getContentItem("urn:iks-project:fise:text:content-item:person", CONTEXT); //add three text annotations to be consumed by this test @@ -118,7 +123,17 @@ public class TestLocationEnhancementEngi getTextAnnotation(ci, ORGANISATION, CONTEXT, OntologicalClasses.DBPEDIA_ORGANISATION); getTextAnnotation(ci, PLACE, CONTEXT, OntologicalClasses.DBPEDIA_PLACE); //perform the computation of the enhancements - locationEnhancementEngine.computeEnhancements(ci); + try { + locationEnhancementEngine.computeEnhancements(ci); + } catch (EngineException e) { + if(e.getCause() instanceof UnknownHostException) { + log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause()); + return; + } else if(e.getCause() instanceof SocketTimeoutException){ + log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause()); + return; + } + } // ... and test the results /* * TODO: rw 20100617 Modified: incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java?rev=1042736&r1=1042735&r2=1042736&view=diff ============================================================================== --- incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java (original) +++ incubator/stanbol/trunk/fise/ext/org.geonames/src/test/java/eu/iksproject/fise/ext/org/geonames/TestScore.java Mon Dec 6 17:28:38 2010 @@ -1,5 +1,9 @@ package eu.iksproject.fise.ext.org.geonames; +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.net.UnknownHostException; + import org.geonames.Style; import org.geonames.Toponym; import org.geonames.ToponymSearchCriteria; @@ -27,14 +31,24 @@ public class TestScore extends Assert{ searchCriteria.setName("Zealand"); searchCriteria.setStyle(Style.FULL); searchCriteria.setMaxRows(5); - ToponymSearchResult searchResult = WebService.search(searchCriteria); - int i = 0; - for (Toponym toponym : searchResult.getToponyms()) { - i++; - log.info("Result "+i+" "+ toponym.getGeoNameId()+" score= "+toponym.getScore()); - assertTrue(toponym.getScore() != null); - assertTrue(toponym.getScore()>= Double.valueOf(0)); - assertTrue(toponym.getScore()<= Double.valueOf(100)); + try { + ToponymSearchResult searchResult = WebService.search(searchCriteria); + int i = 0; + for (Toponym toponym : searchResult.getToponyms()) { + i++; + log.info("Result "+i+" "+ toponym.getGeoNameId()+" score= "+toponym.getScore()); + assertTrue(toponym.getScore() != null); + assertTrue(toponym.getScore()>= Double.valueOf(0)); + assertTrue(toponym.getScore()<= Double.valueOf(100)); + } + } catch(IOException e){ + if(e instanceof UnknownHostException) { + log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause()); + } else if(e instanceof SocketTimeoutException){ + log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause()); + } else { + throw e; + } } } @@ -44,13 +58,23 @@ public class TestScore extends Assert{ searchCriteria.setName("New York"); searchCriteria.setStyle(Style.FULL); searchCriteria.setMaxRows(1); - ToponymSearchResult searchResult = WebService.search(searchCriteria); - int testGeonamesId = searchResult.getToponyms().iterator().next().getGeoNameId(); - for(Toponym hierarchy : WebService.hierarchy(testGeonamesId, null, Style.FULL)){ - //this service does not provide an score, so test if 1.0 is returned - assertTrue(hierarchy.getScore() != null); - assertTrue(hierarchy.getScore().equals(Double.valueOf(1.0))); - } + try { + ToponymSearchResult searchResult = WebService.search(searchCriteria); + int testGeonamesId = searchResult.getToponyms().iterator().next().getGeoNameId(); + for(Toponym hierarchy : WebService.hierarchy(testGeonamesId, null, Style.FULL)){ + //this service does not provide an score, so test if 1.0 is returned + assertTrue(hierarchy.getScore() != null); + assertTrue(hierarchy.getScore().equals(Double.valueOf(1.0))); + } + } catch(IOException e){ + if(e instanceof UnknownHostException) { + log.warn("Unable to test LocationEnhancemetEngine when offline! -> skipping this test",e.getCause()); + } else if(e instanceof SocketTimeoutException){ + log.warn("Seams like the geonames.org webservice is currently unavailable -> skipping this test",e.getCause()); + } else { + throw e; + } + } } }
