This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test to read metadata. Still trying to make it work
- Loading branch information
1 parent
b8c869c
commit 12067cd
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...c/trustedintermediary/external/azure/AzureStorageAccountPartnerMetadataStorageTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.azure | ||
|
||
import com.azure.storage.blob.BlobClient | ||
import com.azure.storage.blob.BlobContainerClient | ||
import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext | ||
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadata | ||
import gov.hhs.cdc.trustedintermediary.external.jackson.Jackson | ||
import gov.hhs.cdc.trustedintermediary.wrappers.formatter.Formatter | ||
import spock.lang.Specification | ||
|
||
import java.time.Instant | ||
import java.nio.charset.StandardCharsets | ||
|
||
class AzureStorageAccountPartnerMetadataStorageTest extends Specification { | ||
|
||
def setup() { | ||
TestApplicationContext.reset() | ||
TestApplicationContext.init() | ||
} | ||
|
||
def "successfully read metadata"() { | ||
given: "A mock BlobClient and a successful download" | ||
def expectedUniqueId = "uniqueId" | ||
def expectedSender = "sender" | ||
def expectedReceiver = "receiver" | ||
def expectedTimestamp = Instant.parse("2023-12-04T18:51:48.941875Z") | ||
def expectedHash = "abcd" | ||
PartnerMetadata expectedMetadata = new PartnerMetadata(expectedUniqueId, expectedSender, expectedReceiver, expectedTimestamp, expectedHash) | ||
String content = '''{ | ||
"uniqueId": "${expectedUniqueId}", | ||
"sender": "${expectedSender}", | ||
"receiver": "${expectedReceiver}", | ||
"timestamp": "${expectedTimestamp}", | ||
"hash": "${expectedHash}" | ||
}''' | ||
|
||
def storageService = AzureStorageAccountPartnerMetadataStorage.getInstance() | ||
def metadataFileName = storageService.getMetadataFileName(expectedUniqueId) | ||
|
||
def mockBlobClient = Mock(BlobClient) | ||
mockBlobClient.downloadContent() >> content.getBytes(StandardCharsets.UTF_8) | ||
TestApplicationContext.register(BlobClient, mockBlobClient) | ||
|
||
def mockContainerClient = GroovyMock(BlobContainerClient) | ||
storageService.metaClass.getContainerClient >> { -> mockContainerClient } | ||
mockContainerClient.getBlobClient(metadataFileName) >> mockBlobClient | ||
TestApplicationContext.register(BlobContainerClient, mockContainerClient) | ||
|
||
TestApplicationContext.register(Formatter, Jackson.getInstance()) | ||
TestApplicationContext.injectRegisteredImplementations() | ||
|
||
when: "readMetadata is called" | ||
PartnerMetadata metadata = storageService.readMetadata(expectedUniqueId) | ||
|
||
then: "The metadata is returned correctly" | ||
metadata == expectedMetadata | ||
} | ||
} |