generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* unit tests: PartnerMetadataOrchestrator: getMetadat retrieves metadata successfully when receiver is present and sentSubmissionId is missing. SuncRetryTask : should handle thread interruption. * unit test for readMetadata * readMetadata unhappy path unit test * saveMetadata happy path works - unit test * saveMetadata unhappy path works - unit test * refactoring variable type to def * unit test: convertAndSend logs event when submissionId is null * added sentSubmissionId to reflect changes in main
- Loading branch information
1 parent
873e6ab
commit a21afb9
Showing
4 changed files
with
173 additions
and
11 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) | ||
} | ||
} |
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