Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
bd159730
Commit
bd159730
authored
Jan 17, 2022
by
Piotr Gawron
Browse files
handle properly 500 responses from mesh API
parent
b411aeee
Pipeline
#51347
failed with stage
in 11 minutes and 40 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java
View file @
bd159730
...
...
@@ -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
;
}
...
...
annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java
View file @
bd159730
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment