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

handle properly 500 responses from mesh API

parent b411aeee
Pipeline #51347 failed with stage
in 11 minutes and 40 seconds
......@@ -104,7 +104,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* @throws AnnotatorException
* thrown when there is a problem with accessing mesh database
*/
public MeSH getMeSH(final MiriamData meshID) throws AnnotatorException {
public MeSH getMeSH(final MiriamData meshID) {
if (meshID == null || meshID.getResource() == null) {
throw new InvalidArgumentException("mesh cannot be null ");
}
......@@ -128,7 +128,8 @@ public class MeSHParser extends CachableInterface implements IExternalService {
try {
mesh = getMeSHByIdFromDB(meshID);
} catch (SourceNotAvailable e) {
throw new AnnotatorException("Problem with accessing MeSH database", e);
logger.error("Problem with accessing MeSH database", e);
return null;
}
}
if (mesh != null) {
......@@ -289,7 +290,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
* @throws AnnotatorException
* thrown when there is problem with accessing mesh db
*/
public boolean isValidMeshId(final MiriamData meshId) throws AnnotatorException {
public boolean isValidMeshId(final MiriamData meshId) {
if (meshId == null) {
return false;
}
......
......@@ -17,14 +17,11 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
import lcsb.mapviewer.annotation.AnnotationTestFunctions;
import lcsb.mapviewer.annotation.cache.GeneralCacheInterface;
import lcsb.mapviewer.annotation.cache.SourceNotAvailable;
import lcsb.mapviewer.annotation.cache.WebPageDownloader;
import lcsb.mapviewer.annotation.data.MeSH;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
......@@ -65,6 +62,12 @@ public class MeSHParserTest extends AnnotationTestFunctions {
assertFalse(meshParser.isValidMeshId(null));
}
@Test
public void testIsValidMeshWeirdId() throws Exception {
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "-1");
assertFalse(meshParser.isValidMeshId(meshID));
}
@Test
public void testIsValidWithSpace() throws Exception {
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "some disease");
......@@ -103,22 +106,6 @@ public class MeSHParserTest extends AnnotationTestFunctions {
assertEquals(1, mesh.getSynonyms().size());
}
@Test(expected = AnnotatorException.class)
public void testGetMEshWithNetworkProblems() throws Exception {
// Parkinson disease
MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "D004298");
MeSHParser parserUnderTest = new MeSHParser(new ObjectMapper());
WebPageDownloader webPageDownloader = Mockito.mock(WebPageDownloader.class);
when(webPageDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class)))
.thenThrow(new IOException());
parserUnderTest.setWebPageDownloader(webPageDownloader);
parserUnderTest.getMeSH(meshID);
}
/**
* @throws Exception
*/
@Test
public void testExternalDBStatus() throws Exception {
ExternalServiceStatus status = meshParser.getServiceStatus();
......@@ -187,7 +174,7 @@ public class MeSHParserTest extends AnnotationTestFunctions {
when(mockDownloader.getFromNetwork(anyString(), anyString(), nullable(String.class)))
.thenThrow(new IOException());
meshParser.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.DOWN, meshParser.getServiceStatus().getStatus());
assertEquals(ExternalServiceStatusType.CHANGED, meshParser.getServiceStatus().getStatus());
} finally {
meshParser.setWebPageDownloader(downloader);
}
......
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