Skip to content

Commit 1e0ea53

Browse files
authored
Merge pull request #10 from hmcts/feature/amp-151-validation
feature: api-151 validate webhook url with latest api
2 parents ca2cef9 + 0b7c2a5 commit 1e0ea53

File tree

7 files changed

+8
-16
lines changed

7 files changed

+8
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ apply {
3030
}
3131

3232
dependencies {
33-
implementation(group: 'uk.gov.hmcts.cp', name: 'api-cp-crime-hearing-case-event-subscription', version: '1.0.0')
33+
implementation(group: 'uk.gov.hmcts.cp', name: 'api-cp-crime-hearing-case-event-subscription', version: '1.0.0-cc7de31')
3434

3535
// This is proving to be a real puzzle. This is actually included in the api published pom
3636
// ( though with scope of "runtime" )

gradle/dependencies/spring-core.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dependencies {
22
implementation "org.springframework.boot:spring-boot-starter-web"
33
implementation "org.springframework.boot:spring-boot-starter-aspectj"
44
implementation "org.springframework.boot:spring-boot-starter-actuator"
5+
implementation "org.springframework.boot:spring-boot-starter-validation"
56

67
testImplementation "org.springframework.boot:spring-boot-starter-webmvc-test"
78
testImplementation "org.springframework.boot:spring-boot-starter-test"

src/main/java/uk/gov/hmcts/cp/mappers/SubscriptionMapper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import uk.gov.hmcts.cp.openapi.model.EventType;
1212
import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint;
1313

14-
import java.net.URI;
1514
import java.util.List;
1615

1716
import static java.util.stream.Collectors.toList;
@@ -38,7 +37,6 @@ static String mapFromNotificationEndpoint(final NotificationEndpoint notificatio
3837
}
3938

4039
static NotificationEndpoint mapToNotificationEndpoint(final String endpointUrl) {
41-
final URI uri = URI.create(endpointUrl);
42-
return NotificationEndpoint.builder().webhookUrl(uri).build();
40+
return NotificationEndpoint.builder().webhookUrl(endpointUrl).build();
4341
}
4442
}

src/test/java/uk/gov/hmcts/cp/integration/SubscriptionControllerValidationTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint;
1010
import uk.gov.hmcts.cp.repositories.SubscriptionRepository;
1111

12-
import java.net.URI;
1312
import java.util.List;
1413

1514
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@@ -24,7 +23,7 @@ class SubscriptionControllerValidationTest extends IntegrationTestBase {
2423
SubscriptionRepository subscriptionRepository;
2524

2625
NotificationEndpoint notificationEndpoint = NotificationEndpoint.builder()
27-
.webhookUrl(URI.create("https://my-callback-url"))
26+
.webhookUrl("https://my-callback-url")
2827
.build();
2928
ClientSubscriptionRequest request = ClientSubscriptionRequest.builder()
3029
.notificationEndpoint(notificationEndpoint)
@@ -42,10 +41,8 @@ void bad_event_type_should_return_400() throws Exception {
4241
.andExpect(content().string(""));
4342
}
4443

45-
// TODO - decide how to best validate the incoming url and enable this test once done
4644
@Test
47-
@Disabled
48-
void bad_url_should_return_400() throws Exception {
45+
void webhook_bad_url_should_return_400() throws Exception {
4946
String body = new ObjectMapper().writeValueAsString(request)
5047
.replace("https://my-callback-url", "not-a-url");
5148
mockMvc.perform(post("/client-subscriptions")

src/test/java/uk/gov/hmcts/cp/integration/SubscriptionGetControllerIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint;
1010
import uk.gov.hmcts.cp.repositories.SubscriptionRepository;
1111

12-
import java.net.URI;
1312
import java.util.List;
1413
import java.util.UUID;
1514

@@ -27,7 +26,7 @@ class SubscriptionGetControllerIntegrationTest extends IntegrationTestBase {
2726
SubscriptionRepository subscriptionRepository;
2827

2928
NotificationEndpoint notificationEndpoint = NotificationEndpoint.builder()
30-
.webhookUrl(URI.create("https://my-callback-url"))
29+
.webhookUrl("https://my-callback-url")
3130
.build();
3231
ClientSubscriptionRequest request = ClientSubscriptionRequest.builder()
3332
.notificationEndpoint(notificationEndpoint)

src/test/java/uk/gov/hmcts/cp/integration/SubscriptionSaveControllerIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint;
1212
import uk.gov.hmcts.cp.repositories.SubscriptionRepository;
1313

14-
import java.net.URI;
1514
import java.util.List;
1615

1716
import static org.assertj.core.api.Assertions.assertThat;
18-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
1917
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
2018
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2119
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@@ -29,7 +27,7 @@ class SubscriptionSaveControllerIntegrationTest extends IntegrationTestBase {
2927
SubscriptionRepository subscriptionRepository;
3028

3129
NotificationEndpoint notificationEndpoint = NotificationEndpoint.builder()
32-
.webhookUrl(URI.create("https://my-callback-url"))
30+
.webhookUrl("https://my-callback-url")
3331
.build();
3432
ClientSubscriptionRequest request = ClientSubscriptionRequest.builder()
3533
.notificationEndpoint(notificationEndpoint)

src/test/java/uk/gov/hmcts/cp/mappers/SubscriptionMapperTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import uk.gov.hmcts.cp.openapi.model.ClientSubscriptionRequest;
88
import uk.gov.hmcts.cp.openapi.model.NotificationEndpoint;
99

10-
import java.net.URI;
1110
import java.time.OffsetDateTime;
1211
import java.util.List;
1312
import java.util.UUID;
@@ -22,7 +21,7 @@ class SubscriptionMapperTest {
2221

2322
UUID clientNotificationId = UUID.fromString("d730c6e1-66ba-4ef0-a3dd-0b9928faa76d");
2423
NotificationEndpoint notificationEndpoint = NotificationEndpoint.builder()
25-
.webhookUrl(URI.create("https://example.com"))
24+
.webhookUrl("https://example.com")
2625
.build();
2726
OffsetDateTime createdAt = OffsetDateTime.now().minusDays(2);
2827
OffsetDateTime updatedAt = OffsetDateTime.now().minusHours(2);

0 commit comments

Comments
 (0)