-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/amp 151 get subscriptiom #7
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b00fb33
feature: amp-151 alpha sort event types in database
coling01 d8e1ce7
feature: amp-151 afixup import wildcards to 99 i.e. remove import .*
coling01 e9ac7f2
feature: amp-151 add get endpoint and tidy ups
coling01 3a90455
feature: amp-151 add get endpoint and tidy up including 404 handler
coling01 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
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
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
2 changes: 1 addition & 1 deletion
2
...java/uk/gov/hmcts/cp/model/EventType.java → ...k/gov/hmcts/cp/model/EntityEventType.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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| package uk.gov.hmcts.cp.model; | ||
|
|
||
| public enum EventType { | ||
| public enum EntityEventType { | ||
| PCR, | ||
| CUSTODIAL_RESULT | ||
| } |
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
6 changes: 3 additions & 3 deletions
6
src/main/resources/db/migration/V1.001__subscription_schema.sql
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| create table client_subscription ( | ||
| id uuid primary key not null, | ||
| event_types varchar(2048) not null, | ||
| notification_endpoint text not null, | ||
| event_types varchar(128) not null, | ||
| notification_endpoint varchar(2048) not null, | ||
| created_at timestamp not null, | ||
| updated_at timestamp | ||
| updated_at timestamp not null | ||
| ); |
20 changes: 20 additions & 0 deletions
20
src/test/java/uk/gov/hmcts/cp/controllers/GlobalExceptionHandler.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,20 @@ | ||
| package uk.gov.hmcts.cp.controllers; | ||
|
|
||
| import jakarta.persistence.EntityNotFoundException; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @RestControllerAdvice | ||
| public class GlobalExceptionHandler { | ||
|
|
||
| private static final String NOT_FOUND_MESSAGE = "No row with the given identifier exists"; | ||
|
|
||
| @ExceptionHandler(EntityNotFoundException.class) | ||
| public ResponseEntity<String> handleNotFoundException(final EntityNotFoundException exception) { | ||
| return ResponseEntity | ||
| .status(HttpStatus.NOT_FOUND) | ||
| .body(NOT_FOUND_MESSAGE); | ||
| } | ||
| } | ||
coling01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
38 changes: 0 additions & 38 deletions
38
src/test/java/uk/gov/hmcts/cp/integration/SubscriptionControllerIntegrationTest.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/test/java/uk/gov/hmcts/cp/integration/SubscriptionControllerValidationTest.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,57 @@ | ||
| package uk.gov.hmcts.cp.integration; | ||
|
|
||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.MediaType; | ||
| import tools.jackson.databind.ObjectMapper; | ||
| import uk.gov.hmcts.cp.openapi.model.ClientSubscriptionRequest; | ||
| import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint; | ||
| import uk.gov.hmcts.cp.repositories.SubscriptionRepository; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
|
|
||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
| import static uk.gov.hmcts.cp.openapi.model.EventType.CUSTODIAL_RESULT; | ||
| import static uk.gov.hmcts.cp.openapi.model.EventType.PCR; | ||
|
|
||
| class SubscriptionControllerValidationTest extends IntegrationTestBase { | ||
|
|
||
| @Autowired | ||
| SubscriptionRepository subscriptionRepository; | ||
|
|
||
| NotificationEndpoint notificationEndpoint = NotificationEndpoint.builder() | ||
| .webhookUrl(URI.create("https://my-callback-url")) | ||
| .build(); | ||
| ClientSubscriptionRequest request = ClientSubscriptionRequest.builder() | ||
| .notificationEndpoint(notificationEndpoint) | ||
| .eventTypes(List.of(PCR, CUSTODIAL_RESULT)) | ||
| .build(); | ||
|
|
||
| @Test | ||
| void bad_event_type_should_return_400() throws Exception { | ||
| String body = new ObjectMapper().writeValueAsString(request) | ||
| .replace("PCR", "BAD"); | ||
| mockMvc.perform(post("/client-subscriptions") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(body)) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(content().string("")); | ||
| } | ||
|
|
||
| // TODO - decide how to best validate the incoming url and enable this test once done | ||
| @Test | ||
| @Disabled | ||
| void bad_url_should_return_400() throws Exception { | ||
| String body = new ObjectMapper().writeValueAsString(request) | ||
| .replace("https://my-callback-url", "not-a-url"); | ||
| mockMvc.perform(post("/client-subscriptions") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(body)) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(content().string("")); | ||
| } | ||
| } |
Oops, something went wrong.
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.