refactor(azure): enable mocking of MSI builder via factory method
All Submissions:
- [YES] I have added an explanation of what changes in this merge do and why we should include it?
- [NO] I have updated the documentation accordingly.
- [YES] I have added tests to cover my changes.
- [YES] All new and existing tests passed.
- [YES] My code follows the code style of this project.
- [NA] I ran lint checks locally prior to submission.
What is the issue or story related to the change?
Unit tests for AzureServicePrincipal.getMSIToken() were causing long timeouts (~30-60s) because they attempted to connect to Azure's MSI endpoint in non-Azure environments.
Change details:
- Added protected factory method
createManagedIdentityCredentialBuilder()inAzureServicePrincipal.java - Updated
getMSIToken()to use the factory method instead of direct instantiation - Updated tests to mock the factory method via
@Spy, enabling proper unit testing - Tests now verify correct scope, method calls, and both success/failure paths
This follows the existing pattern used for createworkloadIdentityClientBuilder() and createClientSecretBuilder().
Test coverage:
-
TestGenerateMsiToken()- verifies successful token retrieval with proper scope -
TestGenerateMsiToken_failure()- verifies AppException on null token
All 7 tests pass (1 skipped - end-to-end test requiring Azure environment).
Does this introduce a breaking change?
- [NO]
Other information
Files changed:
src/main/java/org/opengroup/osdu/azure/util/AzureServicePrincipal.javasrc/test/java/org/opengroup/osdu/azure/util/AzureServicePrincipalTest.java