From 5573b549c57a87d96786505cf3008e0509354e75 Mon Sep 17 00:00:00 2001 From: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:38:48 -0500 Subject: [PATCH 01/13] Added helper method for failed delivery status - WIP added constructer methods to PartnerMetadata --- .../etor/EtorDomainRegistration.java | 2 ++ .../etor/metadata/PartnerMetadata.java | 11 +++++++++ .../metadata/PartnerMetadataOrchestrator.java | 24 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index bf3d0eaef..5f8716f85 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -160,9 +160,11 @@ DomainResponse handleOrders(DomainRequest request) { sendOrderUseCase.convertAndSend(orders, receivedSubmissionId); } catch (FhirParseException e) { logger.logError("Unable to parse order request", e); + //helper return domainResponseHelper.constructErrorResponse(400, e); } catch (UnableToSendOrderException e) { logger.logError("Unable to send order", e); + //helper return domainResponseHelper.constructErrorResponse(400, e); } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java index 069070102..65f50e47a 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java @@ -64,4 +64,15 @@ public PartnerMetadata withReceiver(String receiver) { this.hash, this.deliveryStatus); } + + public PartnerMetadata withDeliveryStatus(PartnerMetadataStatus deliveryStatus) { + return new PartnerMetadata( + this.receivedSubmissionId, + this.sentSubmissionId, + this.sender, + this.receiver, + this.timeReceived, + this.hash, + deliveryStatus); + } } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java index 13bf4f30d..80cf1f06d 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java @@ -174,4 +174,28 @@ String getReceiverName(String responseBody) throws FormatterProcessingException return organizationId + "." + service; } + + public void setMetadataStatus (String submissionId, PartnerMetadataStatus metadataStatus) throws PartnerMetadataException { + if (submissionId == null) { + return; + } + + Optional optionalPartnerMetadata = + partnerMetadataStorage.readMetadata(submissionId); + if (optionalPartnerMetadata.isEmpty()) { + logger.logWarning( + "Metadata not found for submissionId: {}", submissionId); + return; + } + + PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); + + if (partnerMetadata.deliveryStatus().equals(metadataStatus)) { + return; + } + + logger.logInfo("Updating metadata delivery status {} with submissionId: {}", metadataStatus, submissionId); + partnerMetadata = partnerMetadata.withDeliveryStatus(metadataStatus); + partnerMetadataStorage.saveMetadata(partnerMetadata); + } } From 158eae044f7a7ea08d7480a329ab2205b5472e8e Mon Sep 17 00:00:00 2001 From: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:43:15 -0500 Subject: [PATCH 02/13] WIP - Implementing metadata status help method - Implementing metadata status help method from partnerMetadataOrchestrator to handleOrders --- .../etor/EtorDomainRegistration.java | 11 +++++++++-- .../etor/metadata/PartnerMetadataOrchestrator.java | 11 +++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index 5f8716f85..b85bd42ce 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -15,6 +15,7 @@ import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataException; import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataOrchestrator; import gov.hhs.cdc.trustedintermediary.etor.metadata.PartnerMetadataStorage; +import gov.hhs.cdc.trustedintermediary.etor.metadata.partner.PartnerMetadataStatus; import gov.hhs.cdc.trustedintermediary.etor.operationoutcomes.FhirMetadata; import gov.hhs.cdc.trustedintermediary.etor.orders.Order; import gov.hhs.cdc.trustedintermediary.etor.orders.OrderController; @@ -160,11 +161,17 @@ DomainResponse handleOrders(DomainRequest request) { sendOrderUseCase.convertAndSend(orders, receivedSubmissionId); } catch (FhirParseException e) { logger.logError("Unable to parse order request", e); - //helper + try { + partnerMetadataOrchestrator.setMetadataStatus( + receivedSubmissionId, PartnerMetadataStatus.FAILED); + } catch (PartnerMetadataException innerE) { + logger.logError("Unable to update metadata status", innerE); + // possible domain response? + } return domainResponseHelper.constructErrorResponse(400, e); } catch (UnableToSendOrderException e) { logger.logError("Unable to send order", e); - //helper + // setMetadataStatus(receivedSubmissionId) return domainResponseHelper.constructErrorResponse(400, e); } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java index 80cf1f06d..03e4639b6 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java @@ -175,7 +175,8 @@ String getReceiverName(String responseBody) throws FormatterProcessingException return organizationId + "." + service; } - public void setMetadataStatus (String submissionId, PartnerMetadataStatus metadataStatus) throws PartnerMetadataException { + public void setMetadataStatus(String submissionId, PartnerMetadataStatus metadataStatus) + throws PartnerMetadataException { if (submissionId == null) { return; } @@ -183,8 +184,7 @@ public void setMetadataStatus (String submissionId, PartnerMetadataStatus metada Optional optionalPartnerMetadata = partnerMetadataStorage.readMetadata(submissionId); if (optionalPartnerMetadata.isEmpty()) { - logger.logWarning( - "Metadata not found for submissionId: {}", submissionId); + logger.logWarning("Metadata not found for submissionId: {}", submissionId); return; } @@ -194,7 +194,10 @@ public void setMetadataStatus (String submissionId, PartnerMetadataStatus metada return; } - logger.logInfo("Updating metadata delivery status {} with submissionId: {}", metadataStatus, submissionId); + logger.logInfo( + "Updating metadata delivery status {} with submissionId: {}", + metadataStatus, + submissionId); partnerMetadata = partnerMetadata.withDeliveryStatus(metadataStatus); partnerMetadataStorage.saveMetadata(partnerMetadata); } From a4c78c5b5443b4ef22a83b3f8e8fd1df507b6030 Mon Sep 17 00:00:00 2001 From: halprin Date: Fri, 12 Jan 2024 15:20:34 -0700 Subject: [PATCH 03/13] 610: Mark metadata as failed in a finally block --- .../etor/EtorDomainRegistration.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index b85bd42ce..7b68b66aa 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -156,23 +156,27 @@ DomainResponse handleOrders(DomainRequest request) { logger.logError("Missing required header or empty: RecordId"); } + var markMetadataAsFailed = false; try { orders = orderController.parseOrders(request); sendOrderUseCase.convertAndSend(orders, receivedSubmissionId); } catch (FhirParseException e) { logger.logError("Unable to parse order request", e); - try { - partnerMetadataOrchestrator.setMetadataStatus( - receivedSubmissionId, PartnerMetadataStatus.FAILED); - } catch (PartnerMetadataException innerE) { - logger.logError("Unable to update metadata status", innerE); - // possible domain response? - } + markMetadataAsFailed = true; return domainResponseHelper.constructErrorResponse(400, e); } catch (UnableToSendOrderException e) { logger.logError("Unable to send order", e); - // setMetadataStatus(receivedSubmissionId) + markMetadataAsFailed = true; return domainResponseHelper.constructErrorResponse(400, e); + } finally { + if (markMetadataAsFailed) { + try { + partnerMetadataOrchestrator.setMetadataStatus( + receivedSubmissionId, PartnerMetadataStatus.FAILED); + } catch (PartnerMetadataException innerE) { + logger.logError("Unable to update metadata status", innerE); + } + } } OrderResponse orderResponse = new OrderResponse(orders); From 5731e577ac7ccfacbf63cd941b4d6e3216687744 Mon Sep 17 00:00:00 2001 From: halprin Date: Fri, 12 Jan 2024 15:22:12 -0700 Subject: [PATCH 04/13] 610: Move the public methods on top in PartnerMetadataOrchestrator --- .../metadata/PartnerMetadataOrchestrator.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java index 03e4639b6..60f783190 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java @@ -142,6 +142,33 @@ public Optional getMetadata(String receivedSubmissionId) return Optional.of(partnerMetadata); } + public void setMetadataStatus(String submissionId, PartnerMetadataStatus metadataStatus) + throws PartnerMetadataException { + if (submissionId == null) { + return; + } + + Optional optionalPartnerMetadata = + partnerMetadataStorage.readMetadata(submissionId); + if (optionalPartnerMetadata.isEmpty()) { + logger.logWarning("Metadata not found for submissionId: {}", submissionId); + return; + } + + PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); + + if (partnerMetadata.deliveryStatus().equals(metadataStatus)) { + return; + } + + logger.logInfo( + "Updating metadata delivery status {} with submissionId: {}", + metadataStatus, + submissionId); + partnerMetadata = partnerMetadata.withDeliveryStatus(metadataStatus); + partnerMetadataStorage.saveMetadata(partnerMetadata); + } + String getReceiverName(String responseBody) throws FormatterProcessingException { // the expected json structure for the response is: // { @@ -174,31 +201,4 @@ String getReceiverName(String responseBody) throws FormatterProcessingException return organizationId + "." + service; } - - public void setMetadataStatus(String submissionId, PartnerMetadataStatus metadataStatus) - throws PartnerMetadataException { - if (submissionId == null) { - return; - } - - Optional optionalPartnerMetadata = - partnerMetadataStorage.readMetadata(submissionId); - if (optionalPartnerMetadata.isEmpty()) { - logger.logWarning("Metadata not found for submissionId: {}", submissionId); - return; - } - - PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); - - if (partnerMetadata.deliveryStatus().equals(metadataStatus)) { - return; - } - - logger.logInfo( - "Updating metadata delivery status {} with submissionId: {}", - metadataStatus, - submissionId); - partnerMetadata = partnerMetadata.withDeliveryStatus(metadataStatus); - partnerMetadataStorage.saveMetadata(partnerMetadata); - } } From 46727383f60749ff0093e97a0f1293a8432139b7 Mon Sep 17 00:00:00 2001 From: halprin Date: Fri, 12 Jan 2024 15:34:56 -0700 Subject: [PATCH 05/13] 610: Create metadata when setting its status if it did not exist --- .../trustedintermediary/etor/metadata/PartnerMetadata.java | 4 ++++ .../etor/metadata/PartnerMetadataOrchestrator.java | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java index 65f50e47a..a2ee1e6b6 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadata.java @@ -43,6 +43,10 @@ public PartnerMetadata(String receivedSubmissionId, String hash) { this(receivedSubmissionId, null, null, null, null, hash, null); } + public PartnerMetadata(String receivedSubmissionId, PartnerMetadataStatus deliveryStatus) { + this(receivedSubmissionId, null, null, null, null, null, deliveryStatus); + } + public PartnerMetadata withSentSubmissionId(String sentSubmissionId) { return new PartnerMetadata( this.receivedSubmissionId, diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java index 60f783190..25403b3c0 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java @@ -151,8 +151,9 @@ public void setMetadataStatus(String submissionId, PartnerMetadataStatus metadat Optional optionalPartnerMetadata = partnerMetadataStorage.readMetadata(submissionId); if (optionalPartnerMetadata.isEmpty()) { - logger.logWarning("Metadata not found for submissionId: {}", submissionId); - return; + // there wasn't any metadata given the submission ID, so make one with the status + optionalPartnerMetadata = + Optional.of(new PartnerMetadata(submissionId, metadataStatus)); } PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); From 61fd5e3cf22e551eb93b207136a454400bd2521f Mon Sep 17 00:00:00 2001 From: halprin Date: Fri, 12 Jan 2024 16:02:46 -0700 Subject: [PATCH 06/13] 610: Add unit tests for the PartnerMetadata --- .../etor/metadata/PartnerMetadataTest.groovy | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataTest.groovy index 827d25a0b..f304c3831 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataTest.groovy @@ -78,6 +78,24 @@ class PartnerMetadataTest extends Specification { metadata.deliveryStatus() == PartnerMetadataStatus.PENDING } + def "test constructor with only received submission ID and status"() { + given: + def receivedSubmissionId = "receivedSubmissionId" + def deliverStatus = PartnerMetadataStatus.DELIVERED + + when: + def metadata = new PartnerMetadata(receivedSubmissionId, deliverStatus) + + then: + metadata.receivedSubmissionId() == receivedSubmissionId + metadata.sentSubmissionId() == null + metadata.sender() == null + metadata.receiver() == null + metadata.timeReceived() == null + metadata.hash() == null + metadata.deliveryStatus() == deliverStatus + } + def "test withSentSubmissionId and withReceiver to update PartnerMetadata"() { given: def receivedSubmissionId = "receivedSubmissionId" @@ -101,4 +119,28 @@ class PartnerMetadataTest extends Specification { updatedMetadata.hash() == hash updatedMetadata.deliveryStatus() == status } + + def "test withDeliveryStatus to update PartnerMetadata"() { + given: + def receivedSubmissionId = "receivedSubmissionId" + def sentSubmissionId = "sentSubmissionId" + def sender = "sender" + def receiver = "receiver" + def timeReceived = Instant.now() + def hash = "abcd" + def metadata = new PartnerMetadata(receivedSubmissionId, sentSubmissionId, sender, receiver, timeReceived, hash, PartnerMetadataStatus.PENDING) + + when: + def newStatus = PartnerMetadataStatus.DELIVERED + def updatedMetadata = metadata.withSentSubmissionId(sentSubmissionId).withDeliveryStatus(newStatus) + + then: + updatedMetadata.receivedSubmissionId() == receivedSubmissionId + updatedMetadata.sentSubmissionId() == sentSubmissionId + updatedMetadata.sender() == sender + updatedMetadata.receiver() == receiver + updatedMetadata.timeReceived() == timeReceived + updatedMetadata.hash() == hash + updatedMetadata.deliveryStatus() == newStatus + } } From 56b8deed7b4ff2d16d9e394054fae10d824e465b Mon Sep 17 00:00:00 2001 From: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Date: Sun, 14 Jan 2024 23:17:47 -0500 Subject: [PATCH 07/13] Fixed EtorDomainRegistration Unit Tests --- .../cdc/trustedintermediary/etor/EtorDomainRegistration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index 7b68b66aa..05be94689 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -173,7 +173,7 @@ DomainResponse handleOrders(DomainRequest request) { try { partnerMetadataOrchestrator.setMetadataStatus( receivedSubmissionId, PartnerMetadataStatus.FAILED); - } catch (PartnerMetadataException innerE) { + } catch (PartnerMetadataException | NullPointerException innerE) { logger.logError("Unable to update metadata status", innerE); } } From 829a2a6c63da897b95c2d5311fc40fb5c0c28c86 Mon Sep 17 00:00:00 2001 From: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:51:18 -0500 Subject: [PATCH 08/13] Fixed EtorDomainRegistration Unit Tests correctly - added test for setMetadataStatus throwing correct exception --- .../etor/EtorDomainRegistration.java | 2 +- .../etor/EtorDomainRegistrationTest.groovy | 46 +++++++++++++++++++ .../PartnerMetadataOrchestratorTest.groovy | 6 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java index 05be94689..7b68b66aa 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistration.java @@ -173,7 +173,7 @@ DomainResponse handleOrders(DomainRequest request) { try { partnerMetadataOrchestrator.setMetadataStatus( receivedSubmissionId, PartnerMetadataStatus.FAILED); - } catch (PartnerMetadataException | NullPointerException innerE) { + } catch (PartnerMetadataException innerE) { logger.logError("Unable to update metadata status", innerE); } } diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy index 3f3117830..932eddd74 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/EtorDomainRegistrationTest.groovy @@ -213,6 +213,9 @@ class EtorDomainRegistrationTest extends Specification { mockResponseHelper.constructErrorResponse(expectedStatusCode, _ as Exception) >> new DomainResponse(expectedStatusCode) TestApplicationContext.register(DomainResponseHelper, mockResponseHelper) + def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) + TestApplicationContext.register(PartnerMetadataOrchestrator,mockPartnerMetadataOrchestrator) + TestApplicationContext.injectRegisteredImplementations() when: @@ -241,6 +244,49 @@ class EtorDomainRegistrationTest extends Specification { mockResponseHelper.constructErrorResponse(expectedStatusCode, _ as Exception) >> new DomainResponse(expectedStatusCode) TestApplicationContext.register(DomainResponseHelper, mockResponseHelper) + def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) + TestApplicationContext.register(PartnerMetadataOrchestrator,mockPartnerMetadataOrchestrator) + + TestApplicationContext.injectRegisteredImplementations() + + when: + def res = domainRegistration.handleOrders(request) + def actualStatusCode = res.statusCode + + then: + actualStatusCode == expectedStatusCode + } + + def "handleOrders generates an error response when not being able to send the order even when setMetadataStatus throws an exception"() { + given: + def expectedStatusCode = 400 + + def request = new DomainRequest() + request.headers["recordid"] = "recordId" + + def domainRegistration = new EtorDomainRegistration() + TestApplicationContext.register(EtorDomainRegistration, domainRegistration) + + def mockController = Mock(OrderController) + mockController.parseOrders(_ as DomainRequest) >> new OrderMock(null, null, null) + TestApplicationContext.register(OrderController, mockController) + + def mockUseCase = Mock(SendOrderUseCase) + mockUseCase.convertAndSend(_ as Order, _ as String) >> { + throw new UnableToSendOrderException("error", new NullPointerException()) + } + TestApplicationContext.register(SendOrderUseCase, mockUseCase) + + def mockResponseHelper = Mock(DomainResponseHelper) + mockResponseHelper.constructErrorResponse(expectedStatusCode, _ as UnableToSendOrderException) >> new DomainResponse(expectedStatusCode) + TestApplicationContext.register(DomainResponseHelper, mockResponseHelper) + + def mockPartnerMetadataOrchestrator = Mock(PartnerMetadataOrchestrator) + mockPartnerMetadataOrchestrator.setMetadataStatus(_, PartnerMetadataStatus.FAILED) >> { + throw new PartnerMetadataException("error") + } + TestApplicationContext.register(PartnerMetadataOrchestrator,mockPartnerMetadataOrchestrator) + TestApplicationContext.injectRegisteredImplementations() when: diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index 3dcc755cc..8301525cf 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -265,6 +265,10 @@ class PartnerMetadataOrchestratorTest extends Specification { 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } + def "setMetadataStatus sets status to failed "(){ + + } + def "getReceiverName returns correct receiver name from valid JSON response"() { given: def validJson = "{\"destinations\": [{\"organization_id\": \"org_id\", \"service\": \"service_name\"}]}" @@ -327,4 +331,6 @@ class PartnerMetadataOrchestratorTest extends Specification { then: thrown(FormatterProcessingException) } + + } From 47b9223afea707c9fcb2ed22a019830dead89267 Mon Sep 17 00:00:00 2001 From: tjohnson7021 <86614374+tjohnson7021@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:54:24 -0500 Subject: [PATCH 09/13] Linting --- .../etor/metadata/PartnerMetadataOrchestratorTest.groovy | 3 --- 1 file changed, 3 deletions(-) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index 8301525cf..71e7ce2c3 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -266,7 +266,6 @@ class PartnerMetadataOrchestratorTest extends Specification { } def "setMetadataStatus sets status to failed "(){ - } def "getReceiverName returns correct receiver name from valid JSON response"() { @@ -331,6 +330,4 @@ class PartnerMetadataOrchestratorTest extends Specification { then: thrown(FormatterProcessingException) } - - } From 3da5acf9d6e6285d00143831eba1a9a79f3f4b10 Mon Sep 17 00:00:00 2001 From: rajeev-flexion Date: Mon, 15 Jan 2024 11:14:20 -0600 Subject: [PATCH 10/13] test commit --- .../etor/metadata/PartnerMetadataOrchestratorTest.groovy | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index 71e7ce2c3..5b7340ec1 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -266,6 +266,12 @@ class PartnerMetadataOrchestratorTest extends Specification { } def "setMetadataStatus sets status to failed "(){ + given: + + when: + + then: + } def "getReceiverName returns correct receiver name from valid JSON response"() { From c7261521f3c6b86f19159d0c680584980e60719a Mon Sep 17 00:00:00 2001 From: rajeev-flexion Date: Mon, 15 Jan 2024 11:48:08 -0600 Subject: [PATCH 11/13] added test case for setMetadataStatus to Pending --- .../metadata/PartnerMetadataOrchestratorTest.groovy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index 5b7340ec1..8049ec0af 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -265,13 +265,20 @@ class PartnerMetadataOrchestratorTest extends Specification { 1 * mockPartnerMetadataStorage.saveMetadata(expectedMetadata) } - def "setMetadataStatus sets status to failed "(){ + def "setMetadataStatus sets status to Pending"(){ given: + def submissionId = "13425" + def metadataStatus = PartnerMetadataStatus.PENDING + def optional = Optional.of(new PartnerMetadata("","","","",Instant.now(),"",PartnerMetadataStatus.FAILED)) + mockPartnerMetadataStorage.readMetadata(submissionId) >> optional when: + PartnerMetadataOrchestrator.getInstance().setMetadataStatus(submissionId,metadataStatus) then: - + 1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata partnerMetadata -> + assert partnerMetadata.deliveryStatus() == metadataStatus + } } def "getReceiverName returns correct receiver name from valid JSON response"() { From c70566cf1498ac179f33910e1d4331c6a9ee8462 Mon Sep 17 00:00:00 2001 From: rajeev-flexion Date: Mon, 15 Jan 2024 12:10:43 -0600 Subject: [PATCH 12/13] added test cases for setMetadataStatus --- .../metadata/PartnerMetadataOrchestrator.java | 15 +++++---- .../PartnerMetadataOrchestratorTest.groovy | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java index 25403b3c0..2519557ec 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestrator.java @@ -150,16 +150,15 @@ public void setMetadataStatus(String submissionId, PartnerMetadataStatus metadat Optional optionalPartnerMetadata = partnerMetadataStorage.readMetadata(submissionId); + PartnerMetadata partnerMetadata; if (optionalPartnerMetadata.isEmpty()) { // there wasn't any metadata given the submission ID, so make one with the status - optionalPartnerMetadata = - Optional.of(new PartnerMetadata(submissionId, metadataStatus)); - } - - PartnerMetadata partnerMetadata = optionalPartnerMetadata.get(); - - if (partnerMetadata.deliveryStatus().equals(metadataStatus)) { - return; + partnerMetadata = new PartnerMetadata(submissionId, metadataStatus); + } else { + partnerMetadata = optionalPartnerMetadata.get(); + if (partnerMetadata.deliveryStatus().equals(metadataStatus)) { + return; + } } logger.logInfo( diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index 8049ec0af..cb252df45 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -281,6 +281,37 @@ class PartnerMetadataOrchestratorTest extends Specification { } } + def "setMetadataStatus doesn't update status if status is the same"(){ + given: + def submissionId = "13425" + def metadataStatus = PartnerMetadataStatus.PENDING + def optional = Optional.of(new PartnerMetadata("","","","",Instant.now(),"",metadataStatus)) + mockPartnerMetadataStorage.readMetadata(submissionId) >> optional + + when: + PartnerMetadataOrchestrator.getInstance().setMetadataStatus(submissionId,metadataStatus) + + then: + 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) + } + + def "setMetadataStatus sets status to Pending when there is no metadata"(){ + given: + def submissionId = "13425" + def metadataStatus = PartnerMetadataStatus.DELIVERED + def optional = Optional.empty() + mockPartnerMetadataStorage.readMetadata(submissionId) >> optional + + when: + PartnerMetadataOrchestrator.getInstance().setMetadataStatus(submissionId,metadataStatus) + + then: + 1 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) >> { PartnerMetadata partnerMetadata -> + assert partnerMetadata.deliveryStatus() == metadataStatus + assert partnerMetadata.receivedSubmissionId() == submissionId + } + } + def "getReceiverName returns correct receiver name from valid JSON response"() { given: def validJson = "{\"destinations\": [{\"organization_id\": \"org_id\", \"service\": \"service_name\"}]}" From 38324f4ebcf6c94412cb60ef822d06d3b39c3f74 Mon Sep 17 00:00:00 2001 From: rajeev-flexion Date: Mon, 15 Jan 2024 12:35:43 -0600 Subject: [PATCH 13/13] added test case for setMetadataStatus when submissionId == null --- .../etor/metadata/PartnerMetadataOrchestratorTest.groovy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy index cb252df45..9b35d8632 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/PartnerMetadataOrchestratorTest.groovy @@ -295,6 +295,14 @@ class PartnerMetadataOrchestratorTest extends Specification { 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) } + def "setMetadataStatus doesn't update when submissionId is null"(){ + when: + PartnerMetadataOrchestrator.getInstance().setMetadataStatus(null,PartnerMetadataStatus.DELIVERED) + + then: + 0 * mockPartnerMetadataStorage.saveMetadata(_ as PartnerMetadata) + } + def "setMetadataStatus sets status to Pending when there is no metadata"(){ given: def submissionId = "13425"