-
Notifications
You must be signed in to change notification settings - Fork 0
feat:amp-170 add client to call webhook #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9735797
feat:amp-170 add client to call webhook
baranipek d7b53fc
feat:amp-170 add client to call webhook
baranipek 439d4ae
feat:amp-170 add client to call webhook
baranipek f8b1b0b
feat:amp-170 add client to call webhook
baranipek 761f906
feat:amp-170 add client to call webhook
baranipek e9c79e1
feat:amp-170 add client to call webhook
baranipek 79f0d8e
feat:amp-170 add client to call webhook
baranipek 9e21f4f
feat:amp-170 add client to call webhook
baranipek 6f7f2df
feat:amp-170 add client to call webhook
baranipek 84a6845
Merge branch 'main' into feat/amp-170-call-web-hook-url
baranipek bf0d506
amp-170: add api spec
baranipek 22489d1
amp-170: add api spec
baranipek 0f1f94d
amp-170: add api spec
baranipek b26cbce
amp-170: add api spec
baranipek eebc4d4
amp-170: add api spec
baranipek c2c654e
amp-170: add api spec
baranipek 83e1bc7
amp-170: add api spec
baranipek 59507d4
amp-170: add api spec
baranipek 99e99b9
amp-170: add api spec
baranipek 9ce5067
amp-170: address comments
baranipek 055978f
amp-170: address comments
baranipek e31d38a
amp-170: address comments
baranipek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,15 @@ | ||
| dependencyManagement { | ||
| imports { | ||
| mavenBom "org.springframework.cloud:spring-cloud-dependencies:2025.1.0" | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' | ||
|
|
||
| testImplementation 'org.wiremock.integrations:wiremock-spring-boot:3.2.0' | ||
| testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' | ||
| testImplementation 'org.wiremock:wiremock-standalone:3.3.1' | ||
|
|
||
|
|
||
| } |
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
src/main/java/uk/gov/hmcts/cp/subscription/client/DocumentServiceClient.java
This file contains hidden or 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,18 @@ | ||
| package uk.gov.hmcts.cp.subscription.client; | ||
|
|
||
| import org.springframework.cloud.openfeign.FeignClient; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import uk.gov.hmcts.cp.openapi.model.PcrEventPayload; | ||
|
|
||
| @FeignClient( | ||
| name = "document-service", | ||
| url = "${document-service.url}" | ||
| ) | ||
| public interface DocumentServiceClient { | ||
| @PostMapping( | ||
| value = "/document-service/api/rest/document/metadata", | ||
| consumes = "application/json" | ||
samirgarg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| void updateDocumentMetadata(@RequestBody PcrEventPayload request); | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
src/main/java/uk/gov/hmcts/cp/subscription/services/WebhookInvoiceService.java
This file contains hidden or 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,27 @@ | ||
| package uk.gov.hmcts.cp.subscription.services; | ||
|
|
||
| import feign.FeignException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import uk.gov.hmcts.cp.openapi.model.PcrEventPayload; | ||
| import uk.gov.hmcts.cp.subscription.client.DocumentServiceClient; | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class WebhookInvoiceService { | ||
|
|
||
| private final DocumentServiceClient client; | ||
|
|
||
| public void processInvoiceEvent(final PcrEventPayload payload) { | ||
coling01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log.info("Processing invoice webhook event: {}", payload); | ||
|
|
||
| try { | ||
| client.updateDocumentMetadata(payload); | ||
| log.info("Successfully updated document metadata for invoice event"); | ||
| }catch (FeignException ex) { | ||
coling01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log.error("Failed to update document metadata for invoice event", ex); | ||
| throw ex; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
99 changes: 99 additions & 0 deletions
99
src/test/java/uk/gov/hmcts/cp/subscription/client/DocumentServiceClientTest.java
This file contains hidden or 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,99 @@ | ||
| package uk.gov.hmcts.cp.subscription.client; | ||
|
|
||
| import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.cloud.openfeign.EnableFeignClients; | ||
| import org.springframework.cloud.openfeign.FeignAutoConfiguration; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.test.context.DynamicPropertyRegistry; | ||
| import org.springframework.test.context.DynamicPropertySource; | ||
| import uk.gov.hmcts.cp.openapi.model.PcrEventPayload; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
coling01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
|
|
||
| @SpringBootTest( | ||
| classes = DocumentServiceClientTest.TestConfig.class, | ||
| webEnvironment = SpringBootTest.WebEnvironment.NONE | ||
| ) | ||
| class DocumentServiceClientTest { | ||
|
|
||
| @Configuration | ||
| @EnableFeignClients(clients = DocumentServiceClient.class) | ||
| @Import({ | ||
| FeignAutoConfiguration.class, | ||
| HttpMessageConvertersAutoConfiguration.class | ||
| }) | ||
| static class TestConfig { | ||
| } | ||
|
|
||
| @RegisterExtension | ||
| static WireMockExtension wireMockServer = WireMockExtension.newInstance() | ||
| .options(wireMockConfig().dynamicPort()) | ||
| .build(); | ||
|
|
||
| @Autowired | ||
| private DocumentServiceClient documentServiceClient; | ||
|
|
||
| @DynamicPropertySource | ||
| static void configureProperties(DynamicPropertyRegistry registry) { | ||
| registry.add("document-service.url", wireMockServer::baseUrl); | ||
| registry.add("spring.cloud.discovery.enabled", () -> "false"); | ||
| registry.add("spring.cloud.service-registry.auto-registration.enabled", () -> "false"); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSendPostRequestToDocumentService() { | ||
coling01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| wireMockServer.stubFor(post(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .willReturn(aResponse() | ||
| .withStatus(204))); | ||
|
|
||
| PcrEventPayload payload = new PcrEventPayload(); | ||
| payload.setEventId(UUID.randomUUID()); | ||
|
|
||
| documentServiceClient.updateDocumentMetadata(payload); | ||
|
|
||
| wireMockServer.verify(postRequestedFor(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .withHeader("Content-Type", containing("application/json"))); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldHandleSuccessfulResponse() { | ||
| wireMockServer.stubFor(post(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .willReturn(aResponse() | ||
| .withStatus(200))); | ||
|
|
||
| PcrEventPayload payload = new PcrEventPayload(); | ||
| payload.setEventId(UUID.randomUUID()); | ||
|
|
||
| documentServiceClient.updateDocumentMetadata(payload); | ||
|
|
||
| wireMockServer.verify(1, postRequestedFor( | ||
| urlEqualTo("/document-service/api/rest/document/metadata"))); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSendCorrectPayloadToDocumentService() { | ||
| UUID eventId = UUID.randomUUID(); | ||
|
|
||
| wireMockServer.stubFor(post(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .willReturn(aResponse() | ||
| .withStatus(204))); | ||
|
|
||
| PcrEventPayload payload = new PcrEventPayload(); | ||
| payload.setEventId(eventId); | ||
|
|
||
| documentServiceClient.updateDocumentMetadata(payload); | ||
|
|
||
| wireMockServer.verify(postRequestedFor(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .withHeader("Content-Type", containing("application/json")) | ||
| .withRequestBody(matchingJsonPath("$.eventId", equalTo(eventId.toString())))); | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/test/java/uk/gov/hmcts/cp/subscription/services/WebhookInvoiceServiceTest.java
This file contains hidden or 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,69 @@ | ||
| package uk.gov.hmcts.cp.subscription.services; | ||
|
|
||
| import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.cloud.openfeign.EnableFeignClients; | ||
| import org.springframework.cloud.openfeign.FeignAutoConfiguration; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.test.context.DynamicPropertyRegistry; | ||
| import org.springframework.test.context.DynamicPropertySource; | ||
| import uk.gov.hmcts.cp.openapi.model.PcrEventPayload; | ||
| import uk.gov.hmcts.cp.subscription.client.DocumentServiceClient; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
| import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
|
|
||
| @SpringBootTest( | ||
| classes = WebhookInvoiceServiceTest.TestConfig.class, | ||
| webEnvironment = SpringBootTest.WebEnvironment.NONE | ||
| ) | ||
| class WebhookInvoiceServiceTest { | ||
coling01 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Configuration | ||
| @EnableFeignClients(clients = DocumentServiceClient.class) | ||
| @Import({ | ||
| FeignAutoConfiguration.class, | ||
| HttpMessageConvertersAutoConfiguration.class, | ||
| WebhookInvoiceService.class | ||
| }) | ||
| static class TestConfig { | ||
| } | ||
|
|
||
| @RegisterExtension | ||
| static WireMockExtension wireMockServer = WireMockExtension.newInstance() | ||
| .options(wireMockConfig().dynamicPort()) | ||
| .build(); | ||
|
|
||
| @DynamicPropertySource | ||
| static void configureProperties(DynamicPropertyRegistry registry) { | ||
| registry.add("document-service.url", wireMockServer::baseUrl); | ||
| registry.add("spring.cloud.discovery.enabled", () -> "false"); | ||
| registry.add("spring.cloud.service-registry.auto-registration.enabled", () -> "false"); | ||
| } | ||
|
|
||
| @Autowired | ||
| private WebhookInvoiceService webhookInvoiceService; | ||
|
|
||
| @Test | ||
| void shouldCallDocumentServiceToUpdateMetadata() { | ||
| wireMockServer.stubFor(post(urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .willReturn(aResponse() | ||
| .withStatus(200))); | ||
|
|
||
| PcrEventPayload payload = new PcrEventPayload(); | ||
| payload.setEventId(UUID.randomUUID()); | ||
|
|
||
| webhookInvoiceService.processInvoiceEvent(payload); | ||
|
|
||
| wireMockServer.verify(postRequestedFor( | ||
| urlEqualTo("/document-service/api/rest/document/metadata")) | ||
| .withHeader("Content-Type", containing("application/json"))); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.