Commit c613ea89 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

uniprot tests

parent d3103943
package lcsb.mapviewer.annotation.services.annotators;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
......@@ -118,11 +117,6 @@ public class UniprotAnnotator extends ElementAnnotator implements IExternalServi
logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId);
}
}
} catch (FileNotFoundException exception) {
// this means that entry with a given uniprot id doesn't exist
if (uniprotFound) {
logger.warn(elementUtils.getElementTag(object) + " Invalid uniprot id: " + uniprotId);
}
} catch (IOException exception) {
throw new AnnotatorException(exception);
}
......
......@@ -16,6 +16,8 @@ import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.GeneralCacheWithExclusion;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.services.ExternalServiceStatusType;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
......@@ -29,6 +31,7 @@ public class UniprotAnnotatorTest extends AnnotationTestFunctions {
@Autowired
UniprotAnnotator uniprotAnnotator;
@Before
public void setUp() throws Exception {
}
......@@ -71,6 +74,19 @@ public class UniprotAnnotatorTest extends AnnotationTestFunctions {
}
@Test
public void testAnnotateInvalid2() throws Exception {
try {
Species protein = new GenericProtein("id");
uniprotAnnotator.annotateElement(protein);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAnnotate2() throws Exception {
try {
......@@ -213,6 +229,29 @@ public class UniprotAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testAnnotateWithUniprotServerError() throws Exception {
WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader();
GeneralCacheInterface cache = uniprotAnnotator.getCache();
uniprotAnnotator.setCache(new GeneralCacheWithExclusion(cache, 1));
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString())).thenThrow(new IOException());
uniprotAnnotator.setWebPageDownloader(mockDownloader);
Species protein = new GenericProtein("id");
protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P01308"));
uniprotAnnotator.annotateElement(protein);
fail("Exception expected");
} catch (AnnotatorException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
uniprotAnnotator.setCache(cache);
uniprotAnnotator.setWebPageDownloader(downloader);
}
}
@Test
public void testSimulateDownStatus2() throws Exception {
WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment