-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock Entrez PMIDlookup #112
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, Tim! I have a few comments.
@Test | ||
public void testGetEntrezRecordJson() { | ||
PmidLookup apiService = new PmidLookup(); | ||
@MockBean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to use @MockBean
, the test needs to have @SpringBootTest
and maybe @TestPropertySource("classpath:test-application.properties")
. With this, the test becomes spring aware, and spring will take care of wiring things up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
String pmid = "29249144"; | ||
@BeforeEach | ||
public void setUp() { | ||
mockPmidLookup = mock(PmidLookup.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you add @SpringBootTest
, you will no longer need this method. Spring takes care of resetting the @MockBean
between each test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
JSONObject pmr = apiService.retrievePubMedRecordAsJson(pmid); | ||
assertTrue(pmr.getString("source").contains("Proteome")); | ||
when(mockPmidLookup.retrievePubMedRecordAsJson(pmid)).thenReturn(entrezJson); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I read, this test is just calling the method being mocked. This is not really testing the PmiLookup code.
I think a better approach would be to use wiremock, set the PmiLookup URL to hit that and return json. This way, the PmiLookup code is covered. See here for an example:
Line 42 in b7d4e12
public class DepositIT { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to go with putting the entrez service url in the application.properties and in the IT, it will be the same endpoint except I need to get the wiremock port real time in the IT. I was going make a setter method in PmidLookup
class, does this sound like a good plan for you? I can also emulate what you did with making the entrez service url also a system property. I wasn't sure which would be the better way to go. On one hand it could be overkill having multiple ways to configure this URL (sys property and application.properties), but also using a setter method just for an IT doesn't feel right either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try the following:
- add
httpPort
to@WireMockTest
to set the port, so something like@WireMockTest(httpPort = 9911)
- set the
entrez.url
property tohttp://localhost:9911
in thetest-application.properties
- set the new
PmidLookup.entrezUrl
attribute using a@Value
annotation
Note that I had to go with the Sys prop solution in journal loader because it is not spring boot enabled. Also note that using system props is part of standard spring boot property loading: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config . Not applicable for journal loader, but just an FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool! I thought the port was randomly assigned, but if I can manual set it, all the better! Thanks for the info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Going to wait until the release is complete and will do a rebase with the new version. Then this should be ready for review. |
-Modified to use spring properties -Added JSON ascii file
8d81a2f
to
a17245d
Compare
@@ -155,6 +162,38 @@ | |||
</execution> | |||
</executions> | |||
</plugin> | |||
|
|||
<plugin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, it is declared in pass-nihms-loader/pom.xml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Just one small change noted in #112 (comment) @tsande16 , then I will approve. |
public void testGetPubMedRecordWithHighAsciiChars() { | ||
PmidLookup pmidLookup = new PmidLookup(); | ||
String pmid = "27648456"; | ||
public void testGetPubMedRecordWithHighAsciiChars() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A suggestion to reduce code is to update pmidrecord.json
to have the high ascii character in the pmid_record_ascii.json
title
. Then you can just verify the title in testGetPubMedRecord
and delete testGetPubMedRecordWithHighAsciiChars
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other tests use this pmidrecord.json such as testNewCompliantPublication
, testNewInProcessPublication
, testNewNonCompliantPublication
. Would it be okay to change these tests as well with the high ascii character?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are in TransformAndLoadCompliantIT
, TransformAndLoadInProcessIT
, and TransformAndLoadNonCompliantIT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This now includes the refactored NihmsSubmissionEtlITBase that has the member variables, title
, doi
, and issue
that was used by the inheriting classes.
@MockBean private NihmsTransformLoadCLIRunner nihmsTransformLoadCLIRunner; | ||
|
||
@Value("${pmc.entrez.service.url}") | ||
private String ENTREZ_PATH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be deleted, not being used looks like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,190 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this file now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -54,8 +55,11 @@ public class PmidLookup { | |||
* delayed responses. | |||
* https://www.ncbi.nlm.nih.gov/books/NBK25497/ | |||
*/ | |||
private static final String DEFAULT_ENTREZ_PATH = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary" + | |||
".fcgi?db=pubmed&retmode=json&rettype=abstract&id=%s"; | |||
/*private static final String DEFAULT_ENTREZ_PATH = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>org.eclipse.pass.loader.nihms.NihmsHarvesterCLI</mainClass> | ||
<finalName>nihms-data-harvest-cli</finalName> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to remain here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one I was getting compilation errors. I think there was a recent mvn change or something. I will put it back in to get the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This has been reverted, but will be looked into in the future, per our discussion.
The tests for
EntrezPmidLookupTest
were hitting against the real PubMed Entrez service. In most cases this would work, but if the service was down it would cause failures. This service has now been mocked in the tests.To test:
mvn verify