Skip to content
Snippets Groups Projects
Commit fb7c8012 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

GO connector uses new API

parent 2543a6d2
No related branches found
No related tags found
No related merge requests found
package lcsb.mapviewer.annotation.services.annotators; package lcsb.mapviewer.annotation.services.annotators;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import javax.xml.xpath.XPath; import java.util.List;
import javax.xml.xpath.XPathExpressionException; import java.util.Map;
import javax.xml.xpath.XPathFactory;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Node;
import com.google.gson.Gson;
import com.google.gson.internal.StringMap;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface; import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable; import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
...@@ -20,14 +21,13 @@ import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; ...@@ -20,14 +21,13 @@ import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.annotation.services.IExternalService; import lcsb.mapviewer.annotation.services.IExternalService;
import lcsb.mapviewer.annotation.services.MiriamConnector; import lcsb.mapviewer.annotation.services.MiriamConnector;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamRelationType;
import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Phenotype; import lcsb.mapviewer.model.map.species.Phenotype;
import lcsb.mapviewer.modelutils.map.ElementUtils; import lcsb.mapviewer.modelutils.map.ElementUtils;
...@@ -39,194 +39,194 @@ import lcsb.mapviewer.modelutils.map.ElementUtils; ...@@ -39,194 +39,194 @@ import lcsb.mapviewer.modelutils.map.ElementUtils;
*/ */
public class GoAnnotator extends ElementAnnotator implements IExternalService { public class GoAnnotator extends ElementAnnotator implements IExternalService {
/** /**
* Prefix string used for marking the query in database as query by go term. * Prefix string used for marking the query in database as query by go term.
*/ */
static final String GO_TERM_CACHE_PREFIX = "GO_TERM: "; static final String GO_TERM_CACHE_PREFIX = "GO_TERM: ";
/** /**
* Default class logger. * Default class logger.
*/ */
private Logger logger = Logger.getLogger(GoAnnotator.class); private Logger logger = Logger.getLogger(GoAnnotator.class);
/** /**
* Connector used for accessing data from miriam registry. * Connector used for accessing data from miriam registry.
*/ */
@Autowired @Autowired
private MiriamConnector mc; private MiriamConnector mc;
/** /**
* Object that allows to serialize {@link Go} elements into xml string and * Object that allows to serialize {@link Go} elements into xml string and
* deserialize xml into {@link Go} objects. * deserialize xml into {@link Go} objects.
*/ */
private XmlSerializer<Go> goSerializer; private XmlSerializer<Go> goSerializer;
@Override @Override
public String refreshCacheQuery(Object query) throws SourceNotAvailable { public String refreshCacheQuery(Object query) throws SourceNotAvailable {
String result = null; String result = null;
try { try {
if (query instanceof String) { if (query instanceof String) {
String name = (String) query; String name = (String) query;
if (name.startsWith(GO_TERM_CACHE_PREFIX)) { if (name.startsWith(GO_TERM_CACHE_PREFIX)) {
String term = name.substring(GO_TERM_CACHE_PREFIX.length()); String term = name.substring(GO_TERM_CACHE_PREFIX.length());
MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, term); MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, term);
result = goSerializer.objectToString(getGoElement(md)); result = goSerializer.objectToString(getGoElement(md));
} else if (name.startsWith("http")) { } else if (name.startsWith("http")) {
result = getWebPageContent(name); result = getWebPageContent(name);
} else { } else {
throw new InvalidArgumentException("Don't know what to do with query: " + query); throw new InvalidArgumentException("Don't know what to do with query: " + query);
} }
} else { } else {
throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass());
} }
} catch (IOException | GoSearchException e) { } catch (IOException | GoSearchException e) {
throw new SourceNotAvailable(e); throw new SourceNotAvailable(e);
} }
return result; return result;
} }
/** /**
* Default constructor. Initializes structures used for transforming * Default constructor. Initializes structures used for transforming {@link Go}
* {@link Go} from/to xml. * from/to xml.
*/ */
public GoAnnotator() { public GoAnnotator() {
super(GoAnnotator.class, new Class[] { Phenotype.class, Compartment.class, Complex.class }, true); super(GoAnnotator.class, new Class[] { Phenotype.class, Compartment.class, Complex.class }, true);
goSerializer = new XmlSerializer<>(Go.class); goSerializer = new XmlSerializer<>(Go.class);
} }
@Override @Override
public void annotateElement(BioEntity object) throws AnnotatorException { public void annotateElement(BioEntity object) throws AnnotatorException {
if (isAnnotatable(object)) { if (isAnnotatable(object)) {
MiriamData goTerm = null; MiriamData goTerm = null;
for (MiriamData md : object.getMiriamData()) { for (MiriamData md : object.getMiriamData()) {
if (md.getDataType().equals(MiriamType.GO)) { if (md.getDataType().equals(MiriamType.GO)) {
goTerm = md; goTerm = md;
} }
} }
if (goTerm == null) { if (goTerm == null) {
return; return;
} }
try { try {
Go go = getGoElement(goTerm); Go go = getGoElement(goTerm);
if (go != null) {
String commonName = go.getCommonName(); setFullName((Element) object, go.getCommonName(), new ElementUtils().getElementTag(object, this));
setDescription(object, go.getDescription());
setFullName((Element) object, commonName, new ElementUtils().getElementTag(object, this)); }
String description = go.getDescription(); } catch (GoSearchException e) {
setDescription(object, description); throw new AnnotatorException(e);
} catch (GoSearchException e) { }
throw new AnnotatorException(e); }
} }
}
} /**
* Returns go entry from the Gene Ontology database for the goTerm (identifier).
/** *
* Returns go entry from the Gene Ontology database for the goTerm * @param md
* (identifier). * {@link MiriamData} object referencing to entry in GO database
* * @return entry in Gene Ontology database
* @param md * @throws GoSearchException
* {@link MiriamData} object referencing to entry in GO database * thrown when there is a problem with accessing data in go database
* @return entry in Gene Ontology database */
* @throws GoSearchException protected Go getGoElement(MiriamData md) throws GoSearchException {
* thrown when there is a problem with accessing data in go database Go result = goSerializer.xmlToObject(getCacheNode(GO_TERM_CACHE_PREFIX + md.getResource()));
*/
protected Go getGoElement(MiriamData md) throws GoSearchException { if (result != null) {
Go result = goSerializer.xmlToObject(getCacheNode(GO_TERM_CACHE_PREFIX + md.getResource())); return result;
} else {
if (result != null) { result = new Go();
return result; }
} else {
result = new Go(); String accessUrl = "https://www.ebi.ac.uk/QuickGO/services/ontology/go/terms/" + md.getResource();
} try {
String page = getWebPageContent(accessUrl);
String accessUrl = "https://www.ebi.ac.uk/QuickGO-Old/GTerm?id=" + md.getResource() + "&format=oboxml";
try { Gson gson = new Gson();
String tmp = getWebPageContent(accessUrl);
Map<?, ?> gsonObject = (Map<?, ?>) gson.fromJson(page, HashMap.class);
Node xml = getXmlDocumentFromString(tmp.toString()); Double hits = (Double) gsonObject.get("numberOfHits");
if (hits < 1) {
// XPath is here used to locate parts of an XML document return null;
XPath xpath = XPathFactory.newInstance().newXPath(); }
List<?> objects = (List<?>) gsonObject.get("results");
// Locate the term name and print it out
String commonName = xpath.compile("/obo/term/name").evaluate(xml); StringMap<?> object = (StringMap<?>) objects.get(0);
String description = xpath.compile("/obo/term/def/defstr").evaluate(xml); result.setGoTerm((String) object.get("id"));
result.setCommonName(commonName); result.setCommonName((String) object.get("name"));
result.setDescription(description);
result.setGoTerm(md.getResource()); StringMap<?> descr = (StringMap<?>) object.get("definition");
if (descr != null) {
setCacheValue(GO_TERM_CACHE_PREFIX + md.getResource(), goSerializer.objectToString(result)); result.setDescription((String) descr.get("text"));
return result; }
} catch (IOException e) {
throw new GoSearchException("Problem with accesing go database", e); return result;
} catch (InvalidXmlSchemaException | XPathExpressionException e) { } catch (Exception e) {
throw new GoSearchException("Data from go db have invalid format", e); throw new GoSearchException("Problem with accesing go database", e);
} }
} }
@Override @Override
public ExternalServiceStatus getServiceStatus() { public ExternalServiceStatus getServiceStatus() {
ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl());
GeneralCacheInterface cacheCopy = getCache(); GeneralCacheInterface cacheCopy = getCache();
this.setCache(null); this.setCache(null);
try { try {
Compartment compartmentAlias = new Compartment("some_id"); Compartment compartment = new Compartment("some_id");
compartmentAlias.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0046902")); compartment.addMiriamData(new MiriamData(MiriamType.GO, "GO:0046902"));
annotateElement(compartmentAlias); annotateElement(compartment);
if (compartmentAlias.getFullName() == null || compartmentAlias.getFullName().equals("")) { if (compartment.getFullName() == null || compartment.getFullName().equals("")) {
status.setStatus(ExternalServiceStatusType.CHANGED); status.setStatus(ExternalServiceStatusType.CHANGED);
} else if (compartmentAlias.getNotes() == null || compartmentAlias.getNotes().equals("")) { } else if (compartment.getNotes() == null || compartment.getNotes().equals("")) {
status.setStatus(ExternalServiceStatusType.CHANGED); status.setStatus(ExternalServiceStatusType.CHANGED);
} else { } else {
status.setStatus(ExternalServiceStatusType.OK); status.setStatus(ExternalServiceStatusType.OK);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("GeneOntology is down", e); logger.error("GeneOntology is down", e);
status.setStatus(ExternalServiceStatusType.DOWN); status.setStatus(ExternalServiceStatusType.DOWN);
} }
this.setCache(cacheCopy); this.setCache(cacheCopy);
return status; return status;
} }
/** /**
* @return the mc * @return the mc
* @see #mc * @see #mc
*/ */
public MiriamConnector getMc() { public MiriamConnector getMc() {
return mc; return mc;
} }
/** /**
* @param mc * @param mc
* the mc to set * the mc to set
* @see #mc * @see #mc
*/ */
public void setMc(MiriamConnector mc) { public void setMc(MiriamConnector mc) {
this.mc = mc; this.mc = mc;
} }
@Override @Override
public String getCommonName() { public String getCommonName() {
return MiriamType.GO.getCommonName(); return MiriamType.GO.getCommonName();
} }
@Override @Override
public String getUrl() { public String getUrl() {
return MiriamType.GO.getDbHomepage(); return MiriamType.GO.getDbHomepage();
} }
@Override @Override
protected WebPageDownloader getWebPageDownloader() { protected WebPageDownloader getWebPageDownloader() {
return super.getWebPageDownloader(); return super.getWebPageDownloader();
} }
@Override @Override
protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { protected void setWebPageDownloader(WebPageDownloader webPageDownloader) {
super.setWebPageDownloader(webPageDownloader); super.setWebPageDownloader(webPageDownloader);
} }
} }
...@@ -31,208 +31,212 @@ import lcsb.mapviewer.model.map.MiriamType; ...@@ -31,208 +31,212 @@ import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
public class GoAnnotatorTest extends AnnotationTestFunctions { public class GoAnnotatorTest extends AnnotationTestFunctions {
Logger logger = Logger.getLogger(GoAnnotatorTest.class); Logger logger = Logger.getLogger(GoAnnotatorTest.class);
@Autowired @Autowired
GoAnnotator goAnnotator; GoAnnotator goAnnotator;
@Autowired @Autowired
private PermanentDatabaseLevelCacheInterface cache; private PermanentDatabaseLevelCacheInterface cache;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
} }
@Test @Test
public void testContent() throws Exception { public void testContent() throws Exception {
try { try {
Compartment compartmentAlias = new Compartment("id"); Compartment compartmentAlias = new Compartment("id");
compartmentAlias.addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0046902")); compartmentAlias
goAnnotator.annotateElement(compartmentAlias); .addMiriamData(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0046902"));
assertFalse(compartmentAlias.getFullName().equals("")); goAnnotator.annotateElement(compartmentAlias);
assertFalse(compartmentAlias.getNotes().equals("")); assertFalse(compartmentAlias.getFullName().equals(""));
} catch (Exception e) { assertFalse(compartmentAlias.getNotes().equals(""));
e.printStackTrace(); } catch (Exception e) {
throw e; e.printStackTrace();
} throw e;
} }
}
@Test
public void testAnnotate() throws Exception { @Test
try { public void testGetGoData() throws Exception {
MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0042644"); try {
Go go = goAnnotator.getGoElement(md); MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0042644");
assertEquals("GO:0042644", go.getGoTerm()); Go go = goAnnotator.getGoElement(md);
assertNotNull(go.getCommonName()); assertEquals("GO:0042644", go.getGoTerm());
assertNotNull(go.getDescription()); assertNotNull(go.getCommonName());
} catch (Exception e) { assertNotNull(go.getDescription());
e.printStackTrace(); assertTrue(go.getCommonName().toLowerCase().contains("chloroplast nucleoid"));
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test }
public void testAnnotateWhenProblemWithNetworkResponse() throws Exception {
try { @Test
MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0042644"); public void testAnnotateWhenProblemWithNetworkResponse() throws Exception {
GoAnnotator annotator = new GoAnnotator(); try {
annotator.setMc(goAnnotator.getMc()); MiriamData md = new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.GO, "GO:0042644");
WebPageDownloader downloader = Mockito.mock(WebPageDownloader.class); GoAnnotator annotator = new GoAnnotator();
when(downloader.getFromNetwork(anyString())).thenReturn(""); annotator.setMc(goAnnotator.getMc());
annotator.setWebPageDownloader(downloader); WebPageDownloader downloader = Mockito.mock(WebPageDownloader.class);
annotator.getGoElement(md); when(downloader.getFromNetwork(anyString())).thenReturn("");
fail("Exception expected"); annotator.setWebPageDownloader(downloader);
} catch (GoSearchException e) { annotator.getGoElement(md);
assertTrue(e.getMessage().contains("Data from go db have invalid format")); fail("Exception expected");
} catch (Exception e) { } catch (GoSearchException e) {
e.printStackTrace(); assertTrue(e.getMessage().contains("Problem with accesing go database"));
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test(timeout = 15000) }
public void testCachableInterface() throws Exception {
String query = GoAnnotator.GO_TERM_CACHE_PREFIX + "GO:0046902"; @Test(timeout = 15000)
String newRes = "hello"; public void testCachableInterface() throws Exception {
try { String query = GoAnnotator.GO_TERM_CACHE_PREFIX + "GO:0046902";
waitForRefreshCacheQueueToEmpty(); String newRes = "hello";
try {
cache.setCachedQuery(query, goAnnotator.getCacheType(), newRes); waitForRefreshCacheQueueToEmpty();
cache.invalidateByQuery(query, goAnnotator.getCacheType());
cache.setCachedQuery(query, goAnnotator.getCacheType(), newRes);
waitForRefreshCacheQueueToEmpty(); cache.invalidateByQuery(query, goAnnotator.getCacheType());
String res = cache.getStringByQuery(query, goAnnotator.getCacheType()); waitForRefreshCacheQueueToEmpty();
assertNotNull(res); String res = cache.getStringByQuery(query, goAnnotator.getCacheType());
assertFalse("Value wasn't refreshed from db", newRes.equals(res)); assertNotNull(res);
} catch (Exception e) {
e.printStackTrace(); assertFalse("Value wasn't refreshed from db", newRes.equals(res));
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test }
public void testRefreshCacheQueryNotAvailable() throws Exception {
WebPageDownloader downloader = goAnnotator.getWebPageDownloader(); @Test
GeneralCacheInterface originalCache = goAnnotator.getCache(); public void testRefreshCacheQueryNotAvailable() throws Exception {
try { WebPageDownloader downloader = goAnnotator.getWebPageDownloader();
// exclude first cached value GeneralCacheInterface originalCache = goAnnotator.getCache();
goAnnotator.setCache(null); try {
// exclude first cached value
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); goAnnotator.setCache(null);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
goAnnotator.setWebPageDownloader(mockDownloader); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
goAnnotator.refreshCacheQuery("http://google.pl/"); when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
fail("Exception expected"); goAnnotator.setWebPageDownloader(mockDownloader);
} catch (SourceNotAvailable e) { goAnnotator.refreshCacheQuery("http://google.pl/");
} catch (Exception e) { fail("Exception expected");
e.printStackTrace(); } catch (SourceNotAvailable e) {
throw e; } catch (Exception e) {
} finally { e.printStackTrace();
goAnnotator.setWebPageDownloader(downloader); throw e;
goAnnotator.setCache(originalCache); } finally {
} goAnnotator.setWebPageDownloader(downloader);
} goAnnotator.setCache(originalCache);
}
@Test }
public void testRefreshInvalidCacheQuery() throws Exception {
try { @Test
goAnnotator.refreshCacheQuery("invalid_query"); public void testRefreshInvalidCacheQuery() throws Exception {
fail("Exception expected"); try {
} catch (InvalidArgumentException e) { goAnnotator.refreshCacheQuery("invalid_query");
assertTrue(e.getMessage().contains("Don't know what to do")); fail("Exception expected");
} catch (Exception e) { } catch (InvalidArgumentException e) {
e.printStackTrace(); assertTrue(e.getMessage().contains("Don't know what to do"));
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test }
public void testRefreshInvalidCacheQuery2() throws Exception {
try { @Test
goAnnotator.refreshCacheQuery(new Object()); public void testRefreshInvalidCacheQuery2() throws Exception {
fail("Exception expected"); try {
} catch (InvalidArgumentException e) { goAnnotator.refreshCacheQuery(new Object());
assertTrue(e.getMessage().contains("Don't know what to do")); fail("Exception expected");
} catch (Exception e) { } catch (InvalidArgumentException e) {
e.printStackTrace(); assertTrue(e.getMessage().contains("Don't know what to do"));
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test }
public void testRefreshCacheQuery() throws Exception {
try { @Test
String res = goAnnotator.refreshCacheQuery("http://google.pl/"); public void testRefreshCacheQuery() throws Exception {
assertNotNull(res); try {
} catch (Exception e) { String res = goAnnotator.refreshCacheQuery("http://google.pl/");
e.printStackTrace(); assertNotNull(res);
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test(timeout = 15000) }
public void testStatus() throws Exception {
try { @Test(timeout = 15000)
assertEquals(ExternalServiceStatusType.OK, goAnnotator.getServiceStatus().getStatus()); public void testStatus() throws Exception {
} catch (Exception e) { try {
e.printStackTrace(); assertEquals(ExternalServiceStatusType.OK, goAnnotator.getServiceStatus().getStatus());
throw e; } catch (Exception e) {
} e.printStackTrace();
} throw e;
}
@Test }
public void testSimulateDownStatus() throws Exception {
WebPageDownloader downloader = goAnnotator.getWebPageDownloader(); @Test
try { public void testSimulateDownStatus() throws Exception {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); WebPageDownloader downloader = goAnnotator.getWebPageDownloader();
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException()); try {
goAnnotator.setWebPageDownloader(mockDownloader); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
assertEquals(ExternalServiceStatusType.DOWN, goAnnotator.getServiceStatus().getStatus()); when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
} catch (Exception e) { goAnnotator.setWebPageDownloader(mockDownloader);
e.printStackTrace(); assertEquals(ExternalServiceStatusType.DOWN, goAnnotator.getServiceStatus().getStatus());
throw e; } catch (Exception e) {
} finally { e.printStackTrace();
goAnnotator.setWebPageDownloader(downloader); throw e;
} } finally {
} goAnnotator.setWebPageDownloader(downloader);
}
@Test }
public void testSimulateChangedStatus() throws Exception {
WebPageDownloader downloader = goAnnotator.getWebPageDownloader(); @Test
try { public void testSimulateChangedStatus() throws Exception {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); WebPageDownloader downloader = goAnnotator.getWebPageDownloader();
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<obo><term><name/><def><defstr/></def></term></obo>"); try {
goAnnotator.setWebPageDownloader(mockDownloader); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
assertEquals(ExternalServiceStatusType.CHANGED, goAnnotator.getServiceStatus().getStatus()); when(mockDownloader.getFromNetwork(anyString()))
} catch (Exception e) { .thenReturn("{\"numberOfHits\": 1,\"results\": [{\"name\":\"x\"}]}");
e.printStackTrace(); goAnnotator.setWebPageDownloader(mockDownloader);
throw e; assertEquals(ExternalServiceStatusType.CHANGED, goAnnotator.getServiceStatus().getStatus());
} finally { } catch (Exception e) {
goAnnotator.setWebPageDownloader(downloader); e.printStackTrace();
} throw e;
} } finally {
goAnnotator.setWebPageDownloader(downloader);
@Test }
public void testSimulateChangedStatus2() throws Exception { }
WebPageDownloader downloader = goAnnotator.getWebPageDownloader();
try { @Test
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); public void testSimulateChangedStatus2() throws Exception {
when(mockDownloader.getFromNetwork(anyString())).thenReturn("<obo><term><name>some_name</name><def><defstr/></def></term></obo>"); WebPageDownloader downloader = goAnnotator.getWebPageDownloader();
goAnnotator.setWebPageDownloader(mockDownloader); try {
assertEquals(ExternalServiceStatusType.CHANGED, goAnnotator.getServiceStatus().getStatus()); WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
} catch (Exception e) { when(mockDownloader.getFromNetwork(anyString()))
e.printStackTrace(); .thenReturn("{\"numberOfHits\": 1,\"results\": [{}]}");
throw e; goAnnotator.setWebPageDownloader(mockDownloader);
} finally { assertEquals(ExternalServiceStatusType.CHANGED, goAnnotator.getServiceStatus().getStatus());
goAnnotator.setWebPageDownloader(downloader); } catch (Exception e) {
} e.printStackTrace();
} throw e;
} finally {
goAnnotator.setWebPageDownloader(downloader);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment