Skip to content

Normalize error handling for DOI service#134

Merged
markpatton merged 5 commits intomainfrom
1223-book-doi
Mar 20, 2026
Merged

Normalize error handling for DOI service#134
markpatton merged 5 commits intomainfrom
1223-book-doi

Conversation

@markpatton
Copy link
Copy Markdown
Contributor

@markpatton markpatton commented Mar 12, 2026

  • The disabled tests for the doi service were not running because error handling was a little fragile. This pr normalizes the error handling.
  • The code which prevented simultaneous requests for the same DOI has also been removed because it is not needed.
  • Some character encoding issues with responses fixed.
  • I also had to rejigger some tests and add more unit testing to make Sonarqube happy

@markpatton markpatton closed this Mar 12, 2026
@markpatton markpatton reopened this Mar 12, 2026
@markpatton markpatton marked this pull request as draft March 12, 2026 20:00
@markpatton markpatton force-pushed the 1223-book-doi branch 2 times, most recently from 8aa1361 to cb7f12c Compare March 13, 2026 16:51
…multiple requests about the same DOI. Better handle character encoding of responses.
@markpatton markpatton marked this pull request as ready for review March 16, 2026 14:52
@markpatton markpatton requested a review from rpoet-jh March 16, 2026 14:52
*/
@Autowired
public PassDoiServiceController(RefreshableElide refreshableElide) {
this.elideConnector = new ElideConnector(refreshableElide);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using Spring to create and wire up these DOI classes.

You could add the @Service annotation to XrefDoiService and UnpaywallDoiService, and @Component to ExternalDoiServiceConnector and ElideConnector. Then just pass them all into this constructor and set.

By doing this, you could then use @MockitoBean in tests to mock as required, and the constructor below would not be needed.

Copy link
Copy Markdown
Contributor

@rpoet-jh rpoet-jh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on the Spring IOC changes. I reviewed all the code after that, just a few more comments.

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PassDoiServiceControllerTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some of these tests are actually covered in the IT in pass-core-main. For example, testGetXrefMetadata_ServiceError_404 looks to be covered with this test

Normally, Controller tests are ITs. I suggest looking over these tests and seeing if they are already covered in DoiServiceTest. There may be some tests that cannot be tested easily as an integration test, those can stay in this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the permutations with the external services. The integration test can only really test the success path since it hits the external services. If you start mocking the external services, then its not really an integration test anymore. So I just created a separate unit test.

The unit test gives us a way to test the failure paths of the external service integrations like Sonarqube is demanding. There is some test redundancy between the two approaches, but it doesn't seem like a big deal. I will add some documentation to the tests so it is less confusing.

@markpatton
Copy link
Copy Markdown
Contributor Author

@rpoet-jh

Made some updates. See what you think.

@rpoet-jh
Copy link
Copy Markdown
Contributor

@rpoet-jh

Made some updates. See what you think.

Looks good. Only comment is I think you can remove the constructor ExternalDoiServiceConnector(OkHttpClient client) now?

@rpoet-jh
Copy link
Copy Markdown
Contributor

@markpatton oh yeah, to clean up a bunch of the sq warnings, you can remove the public scope from class and methods from the PassDoiServiceControllerTest test.

@rpoet-jh
Copy link
Copy Markdown
Contributor

Only comment is I think you can remove the constructor ExternalDoiServiceConnector(OkHttpClient client) now?

@markpatton you may have missed this small comment.

@markpatton
Copy link
Copy Markdown
Contributor Author

@rpoet-jh

I thought I had all of them! I see they didn't trigger the failure mode. Cleaned up. I wish there was a way to get a list of all the issues on the command line.

@rpoet-jh
Copy link
Copy Markdown
Contributor

@rpoet-jh

I thought I had all of them! I see they didn't trigger the failure mode. Cleaned up. I wish there was a way to get a list of all the issues on the command line.

@markpatton did you push the commit? I don't see it.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@rpoet-jh rpoet-jh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the acceptance tests failed, I think there is some flakiness in that test, I saw it fail a couple days back too. Not caused by this PR, approved.

@markpatton markpatton merged commit 779e115 into main Mar 20, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants