Skip to content

Commit de36374

Browse files
committed
PP-14806 - remove comment and update test name to more descriptive and test the fields are set in the method
1 parent 9b700a8 commit de36374

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/main/java/uk/gov/pay/webhooks/deliveryqueue/managed/SendAttempter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void attemptSend(WebhookDeliveryQueueEntity queueItem) {
7878
callbackUrl = URI.create(webhook.getCallbackUrl().strip()).toURL();
7979
} catch (IllegalArgumentException | MalformedURLException e) {
8080
handleGenericException(queueItem, retryCount, start, e);
81-
// stops code from proceeding if it fails to parse URL
8281
return;
8382
}
8483

src/test/java/uk/gov/pay/webhooks/validations/WebhookRequestValidatorTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import static org.hamcrest.MatcherAssert.assertThat;
2020
import static org.hamcrest.Matchers.is;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2223
import static org.junit.jupiter.api.Assertions.assertNull;
2324
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
import static org.mockito.Mockito.doAnswer;
2426
import static org.mockito.Mockito.mock;
2527
import static org.mockito.Mockito.when;
2628
import static uk.gov.pay.webhooks.app.WebhooksKeys.RESOURCE_IS_LIVE;
@@ -141,11 +143,14 @@ public void httpsCallbackUrlShouldNotThrowError() {
141143
}
142144

143145
@Test
144-
void should_clear_populated_mdc_context_after_validating_create_webhook_request() {
146+
void should_populate_validator_specific_mdc_keys_during_create_webhook_validation_and_clear_them_afterwards() {
147+
var callbackUrlService = mock(CallbackUrlService.class);
148+
var validatorWithMockedCallbackUrlService = new WebhookRequestValidator(callbackUrlService);
149+
145150
MDC.put(MDC_REQUEST_ID_KEY, "request-id");
146151
MDC.put(GATEWAY_ACCOUNT_ID, "existing-gateway-account-id");
147152
MDC.put(SERVICE_EXTERNAL_ID, "existing-service-id");
148-
MDC.put(RESOURCE_IS_LIVE, "false");
153+
MDC.put(RESOURCE_IS_LIVE, "true");
149154

150155
var createWebhookRequest = new CreateWebhookRequest(
151156
"new-service-id",
@@ -156,7 +161,15 @@ void should_clear_populated_mdc_context_after_validating_create_webhook_request(
156161
List.of()
157162
);
158163

159-
assertDoesNotThrow(() -> webhookRequestValidator.validate(createWebhookRequest));
164+
doAnswer(_ -> {
165+
assertEquals("request-id", MDC.get(MDC_REQUEST_ID_KEY));
166+
assertEquals("new-gateway-account-id", MDC.get(GATEWAY_ACCOUNT_ID));
167+
assertEquals("new-service-id", MDC.get(SERVICE_EXTERNAL_ID));
168+
assertEquals("false", MDC.get(RESOURCE_IS_LIVE));
169+
return null;
170+
}).when(callbackUrlService).validateCallbackUrl("https://pay.gov.uk", false);
171+
172+
assertDoesNotThrow(() -> validatorWithMockedCallbackUrlService.validate(createWebhookRequest));
160173

161174
assertThat(MDC.get(MDC_REQUEST_ID_KEY), is("request-id"));
162175
assertNull(MDC.get(GATEWAY_ACCOUNT_ID));

0 commit comments

Comments
 (0)