From 54558a451ccaecf3e51b5f89c3ae8f10a700a227 Mon Sep 17 00:00:00 2001 From: halprin Date: Wed, 25 Oct 2023 15:16:24 -0600 Subject: [PATCH] 613: Remove some of the mocking that is not needed in the unit tests --- .../ReportStreamOrderSenderTest.groovy | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSenderTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSenderTest.groovy index b6b77f44c..e881f2352 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSenderTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/reportstream/ReportStreamOrderSenderTest.groovy @@ -341,36 +341,32 @@ class ReportStreamOrderSenderTest extends Specification { exception.getCause().getClass() == HttpClientException } - def "getRsToken when cache is empty"() { + def "getRsToken when cache is empty we call RS to get a new one"() { given: - def orderSender = ReportStreamOrderSender.getInstance() def mockClient = Mock(HttpClient) - def mockAuthEngine = Mock(AuthEngine) - def mockSecrets = Mock(Secrets) def mockFormatter = Mock(Formatter) def mockCache = Mock(Cache) + + //make the cache empty + mockCache.get(_ as String) >> null + + def freshTokenFromRs = "new token" + mockFormatter.convertJsonToObject(_, _ as TypeReference) >> [access_token: freshTokenFromRs] + TestApplicationContext.register(Formatter, mockFormatter) - TestApplicationContext.register(AuthEngine, mockAuthEngine) + TestApplicationContext.register(AuthEngine, Mock(AuthEngine)) TestApplicationContext.register(HttpClient, mockClient) - TestApplicationContext.register(Secrets, mockSecrets) - mockSecrets.getKey(_ as String) >> "fake private key" TestApplicationContext.register(Cache, mockCache) - mockCache.get(_ as String) >> null - TestApplicationContext.register(OrderSender, orderSender) - TestApplicationContext.injectRegisteredImplementations() + TestApplicationContext.register(Secrets, Mock(Secrets)) - mockAuthEngine.getExpirationDate(_ as String) >> LocalDateTime.now().plus(10, ChronoUnit.SECONDS) - mockAuthEngine.generateSenderToken(_ as String, _ as String, _ as String, _ as String, 300) >> "fake token" - def fakeRsToken = "DogCow" - mockFormatter.convertJsonToObject(_ as String, _ as TypeReference) >> Map.of("access_token", fakeRsToken) - def responseBody = """{"foo":"foo value", "access_token":fake token, "boo":"boo value"}""" - mockClient.post(_ as String, _ as Map, _ as String) >> responseBody + TestApplicationContext.injectRegisteredImplementations() when: - def token = orderSender.getRsToken() + def token = ReportStreamOrderSender.getInstance().getRsToken() then: - token == fakeRsToken + 1 * mockClient.post(_, _, _) + token == freshTokenFromRs } def "getRsToken when cache token is invalid we call RS to get a new one"() { @@ -386,7 +382,7 @@ class ReportStreamOrderSenderTest extends Specification { mockAuthEngine.getExpirationDate(_) >> LocalDateTime.now().plus(10, ChronoUnit.SECONDS) def freshTokenFromRs = "new token" - mockFormatter.convertJsonToObject(_, _ as TypeReference) >> Map.of("access_token", freshTokenFromRs) + mockFormatter.convertJsonToObject(_, _ as TypeReference) >> [access_token: freshTokenFromRs] TestApplicationContext.register(Formatter, mockFormatter) TestApplicationContext.register(AuthEngine, mockAuthEngine)