Reputation:
Can anyone guide me how can I mock azure Blob Storage in Java SDK.
I want to mock connection String, SAS token, endpoint, containerName. If all these got mock, then it will be easy to mock BlobClient.
For reference code is-
public BlobServiceClient blobServiceClient(){ return new BlobServiceClientBuilder().connectionString("TESTING STRING").buildClient(); }
Upvotes: 2
Views: 4245
Reputation: 4602
To workaround this issue you can keep the values of connection String, SAS token, endpoint, ContainerName using their respective variable in a file under the same project. You can mock the blobClient using the below statement by passing the above-mentioned objects in the code.
BlobClient blobClient = new BlobClientBuilder()
.endpoint("<your-storage-account-url>")
.sasToken("<your-sasToken>")
.containerName("mycontainer")
.blobName("myblob")
.buildClient();
or
// Only one "?" is needed here. If the sastoken starts with "?", please removing one "?".
BlobClient blobClient = new BlobClientBuilder()
.endpoint("<your-storage-account-url>" + "/" + "mycontainer" + "/" + "myblob" + "?" + "<your-sasToken>")
.buildClient();
Reference : https://learn.microsoft.com/en-us/java/api/overview/azure/storage-blob-readme?view=azure-java-stable
Upvotes: 0