generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into story-672-no_rs_history_api
- Loading branch information
Showing
3 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
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
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
108 changes: 108 additions & 0 deletions
108
...v/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorageTest.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,108 @@ | ||
package gov.hhs.cdc.trustedintermediary.external.database | ||
|
||
import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext | ||
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadata | ||
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataException | ||
import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataStorage | ||
import gov.hhs.cdc.trustedintermediary.wrappers.DbDao | ||
import spock.lang.Specification | ||
|
||
import java.sql.SQLException | ||
import java.time.Instant | ||
|
||
class DatabasePartnerMetadataStorageTest extends Specification { | ||
|
||
private def mockDao | ||
|
||
def setup() { | ||
TestApplicationContext.reset() | ||
TestApplicationContext.init() | ||
|
||
mockDao = Mock(DbDao) | ||
|
||
TestApplicationContext.register(DbDao, mockDao) | ||
TestApplicationContext.register(PartnerMetadataStorage, DatabasePartnerMetadataStorage.getInstance()) | ||
TestApplicationContext.injectRegisteredImplementations() | ||
} | ||
|
||
def "readMetadata happy path works"() { | ||
given: | ||
def receivedSubmissionId = "receivedSubmissionId" | ||
def mockMetadata = new PartnerMetadata(receivedSubmissionId, "sentSubmissionId", "sender", "receiver", Instant.now(), "hash") | ||
def expectedResult = Optional.of(mockMetadata) | ||
|
||
mockDao.fetchMetadata(_ as String) >> mockMetadata | ||
|
||
when: | ||
def actualResult = DatabasePartnerMetadataStorage.getInstance().readMetadata(receivedSubmissionId) | ||
|
||
then: | ||
actualResult == expectedResult | ||
} | ||
|
||
def "readMetadata unhappy path works"() { | ||
given: | ||
def receivedSubmissionId = "receivedSubmissionId" | ||
mockDao.fetchMetadata(_ as String) >> { throw new SQLException("Something went wrong!") } | ||
|
||
when: | ||
DatabasePartnerMetadataStorage.getInstance().readMetadata(receivedSubmissionId) | ||
|
||
then: | ||
thrown(PartnerMetadataException) | ||
} | ||
|
||
def "saveMetadata happy path works"() { | ||
given: | ||
def receivedSubmissionId = "receivedSubmissionId" | ||
def mockMetadata = new PartnerMetadata( | ||
receivedSubmissionId, | ||
"sentSubmissionId", | ||
"sender", | ||
"receiver", | ||
Instant.now(), | ||
"hash" | ||
) | ||
|
||
when: | ||
DatabasePartnerMetadataStorage.getInstance().saveMetadata(mockMetadata) | ||
|
||
then: | ||
1 * mockDao.upsertMetadata( | ||
mockMetadata.receivedSubmissionId(), | ||
mockMetadata.sentSubmissionId(), | ||
mockMetadata.sender(), | ||
mockMetadata.receiver(), | ||
mockMetadata.hash(), | ||
mockMetadata.timeReceived() | ||
) | ||
} | ||
|
||
def "saveMetadata unhappy path works"() { | ||
given: | ||
def receivedSubmissionId = "receivedSubmissionId" | ||
def mockMetadata = new PartnerMetadata( | ||
receivedSubmissionId, | ||
"sentSubmissionId", | ||
"sender", | ||
"receiver", | ||
Instant.now(), | ||
"hash" | ||
) | ||
|
||
mockDao.upsertMetadata( | ||
mockMetadata.receivedSubmissionId(), | ||
mockMetadata.sentSubmissionId(), | ||
mockMetadata.sender(), | ||
mockMetadata.receiver(), | ||
mockMetadata.hash(), | ||
mockMetadata.timeReceived() | ||
) >> { throw new SQLException("Something went wrong!") } | ||
|
||
when: | ||
DatabasePartnerMetadataStorage.getInstance().saveMetadata(mockMetadata) | ||
|
||
then: | ||
thrown(PartnerMetadataException) | ||
} | ||
} |