Skip to content

Commit e817329

Browse files
Merge pull request #205 from hmcts/dev/AMP433
AMP-433 changes
2 parents f3e682f + 38c9d43 commit e817329

File tree

7 files changed

+32
-14
lines changed

7 files changed

+32
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ apply {
3232
// Sadly, dependabot does not track dependencies in the apply-from files
3333
dependencies {
3434
// Api spec
35-
implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:2.0.0')
35+
implementation('uk.gov.hmcts.cp:api-cp-crime-hearing-case-event-subscription:2.0.1')
3636
implementation('io.swagger.core.v3:swagger-annotations:2.2.46')
3737

3838

src/main/java/uk/gov/hmcts/cp/subscription/controllers/NotificationController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import uk.gov.hmcts.cp.filters.ClientIdResolutionFilter;
2121
import uk.gov.hmcts.cp.openapi.api.InternalApi;
2222
import uk.gov.hmcts.cp.openapi.api.NotificationApi;
23+
import uk.gov.hmcts.cp.openapi.model.EventNotificationPayload;
2324
import uk.gov.hmcts.cp.openapi.model.EventPayload;
2425
import uk.gov.hmcts.cp.servicebus.config.ServiceBusProperties;
2526
import uk.gov.hmcts.cp.servicebus.services.ServiceBusClientService;
@@ -56,7 +57,7 @@ public Optional<NativeWebRequest> getRequest() {
5657
}
5758

5859
@Override
59-
public ResponseEntity<Void> createNotification(
60+
public ResponseEntity<EventNotificationPayload> createNotification(
6061
@Valid @RequestBody final EventPayload eventPayload,
6162
// note the X-Correlation-Id is handled by TracingFilter but we need to declare it because its in the spec
6263
@RequestHeader(value = "X-Correlation-Id", required = false) final UUID xCorrelationId) {
@@ -67,10 +68,10 @@ public ResponseEntity<Void> createNotification(
6768
if (serviceBusConfig.isEnabled()) {
6869
final String pcrEventjson = jsonMapper.toJson(eventPayload);
6970
clientService.queueMessage(NOTIFICATIONS_INBOUND_QUEUE, null, pcrEventjson, 0);
70-
} else {
71-
notificationManager.processPcrNotification(eventPayload);
71+
return new ResponseEntity<>(HttpStatus.ACCEPTED);
7272
}
73-
return new ResponseEntity<>(HttpStatus.ACCEPTED);
73+
final EventNotificationPayload payload = notificationManager.processPcrNotification(eventPayload);
74+
return new ResponseEntity<>(payload, HttpStatus.ACCEPTED);
7475
}
7576

7677
@Override

src/main/java/uk/gov/hmcts/cp/subscription/managers/NotificationManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.http.HttpStatus;
66
import org.springframework.stereotype.Component;
77
import org.springframework.web.server.ResponseStatusException;
8+
import uk.gov.hmcts.cp.openapi.model.EventNotificationPayload;
89
import uk.gov.hmcts.cp.openapi.model.EventPayload;
910
import uk.gov.hmcts.cp.subscription.model.DocumentContent;
1011
import uk.gov.hmcts.cp.subscription.services.CallbackDeliveryService;
@@ -28,11 +29,12 @@ public class NotificationManager {
2829
private final SubscriptionService subscriptionService;
2930
private final CallbackDeliveryService callbackDeliveryService;
3031

31-
public void processPcrNotification(final EventPayload eventPayload) {
32+
public EventNotificationPayload processPcrNotification(final EventPayload eventPayload) {
3233
log.info("processPcrNotification eventId:{} materialId:{}", eventPayload.getEventId(), eventPayload.getMaterialId());
3334
final UUID documentId = notificationService.processInboundEvent(eventPayload);
34-
callbackDeliveryService.submitOutboundPcrEvents(eventPayload, documentId);
35+
final EventNotificationPayload payload = callbackDeliveryService.submitOutboundPcrEvents(eventPayload, documentId);
3536
log.info("processPcrNotification complete eventId:{} documentId:{}", eventPayload.getEventId(), documentId);
37+
return payload;
3638
}
3739

3840
public DocumentContent getPcrDocumentContent(final UUID clientSubscriptionId, final UUID documentId) {

src/main/java/uk/gov/hmcts/cp/subscription/services/CallbackDeliveryService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CallbackDeliveryService {
3838
private final CallbackService callbackService;
3939
private final HmacManager hmacManager;
4040

41-
public void submitOutboundPcrEvents(final EventPayload eventPayload, final UUID documentId) {
41+
public EventNotificationPayload submitOutboundPcrEvents(final EventPayload eventPayload, final UUID documentId) {
4242
final String eventType = eventPayload.getEventType();
4343
final List<ClientEntity> clients = clientEventRepository.findClientsByEventType(eventType);
4444
final EventNotificationPayload eventNotificationPayload = notificationMapper.mapToPayload(documentId, eventPayload);
@@ -59,5 +59,6 @@ public void submitOutboundPcrEvents(final EventPayload eventPayload, final UUID
5959
log.info("Subscriber {} notified via callbackUrl {} for documentId {}", client.getSubscriptionId(), client.getCallbackUrl(), eventNotificationPayload.getDocumentId());
6060
}
6161
}
62+
return eventNotificationPayload;
6263
}
6364
}

src/test/java/uk/gov/hmcts/cp/servicebus/integration/ServiceBusAdminIntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616

1717
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1819

1920
@Slf4j
2021
@SpringBootTest

src/test/java/uk/gov/hmcts/cp/subscription/unit/controllers/NotificationControllerTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.springframework.http.MediaType;
1414
import org.springframework.http.ResponseEntity;
1515
import uk.gov.hmcts.cp.filters.ClientIdResolutionFilter;
16+
import uk.gov.hmcts.cp.openapi.model.EventNotificationPayload;
1617
import uk.gov.hmcts.cp.openapi.model.EventPayload;
1718
import uk.gov.hmcts.cp.servicebus.config.ServiceBusProperties;
1819
import uk.gov.hmcts.cp.servicebus.services.ServiceBusClientService;
@@ -62,20 +63,28 @@ void clearMdcClientId() {
6263

6364
@SneakyThrows
6465
@Test
65-
void service_bus_disabled_should_process_notification_synchronously() {
66+
void service_bus_disabled_should_process_notification_synchronously_and_return_payload() {
67+
final EventNotificationPayload expectedPayload = new EventNotificationPayload();
6668
when(configService.isEnabled()).thenReturn(false);
67-
ResponseEntity<Void> response = notificationController.createNotification(payload, null);
69+
when(notificationManager.processPcrNotification(eq(payload))).thenReturn(expectedPayload);
70+
71+
ResponseEntity<EventNotificationPayload> response = notificationController.createNotification(payload, null);
72+
6873
verify(notificationManager).processPcrNotification(eq(payload));
6974
assertThat(response.getStatusCode()).isEqualTo(ACCEPTED);
75+
assertThat(response.getBody()).isEqualTo(expectedPayload);
7076
}
7177

7278
@Test
73-
void service_bus_enabled_should_queue_to_service_bus() {
79+
void service_bus_enabled_should_queue_to_service_bus_and_return_202_no_body() {
7480
when(configService.isEnabled()).thenReturn(true);
7581
when(jsonMapper.toJson(payload)).thenReturn("payload-json");
76-
ResponseEntity<Void> response = notificationController.createNotification(payload, null);
82+
83+
ResponseEntity<EventNotificationPayload> response = notificationController.createNotification(payload, null);
84+
7785
verify(clientService).queueMessage(NOTIFICATIONS_INBOUND_QUEUE, null, "payload-json", 0);
7886
assertThat(response.getStatusCode()).isEqualTo(ACCEPTED);
87+
assertThat(response.getBody()).isNull();
7988
}
8089

8190
@Test

src/test/java/uk/gov/hmcts/cp/subscription/unit/managers/NotificationManagerTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.http.HttpStatus;
99
import org.springframework.http.MediaType;
1010
import org.springframework.web.server.ResponseStatusException;
11+
import uk.gov.hmcts.cp.openapi.model.EventNotificationPayload;
1112
import uk.gov.hmcts.cp.openapi.model.EventPayload;
1213
import uk.gov.hmcts.cp.subscription.managers.NotificationManager;
1314
import uk.gov.hmcts.cp.subscription.model.DocumentContent;
@@ -60,13 +61,16 @@ class NotificationManagerTest {
6061
.build();
6162

6263
@Test
63-
void processPcrNotification_should_process_deliver() {
64+
void processPcrNotification_should_process_deliver_and_return_notification_payload() {
65+
final EventNotificationPayload expectedPayload = new EventNotificationPayload();
6466
when(notificationService.processInboundEvent(payload)).thenReturn(documentId);
67+
when(callbackDeliveryService.submitOutboundPcrEvents(payload, documentId)).thenReturn(expectedPayload);
6568

66-
notificationManager.processPcrNotification(payload);
69+
final EventNotificationPayload result = notificationManager.processPcrNotification(payload);
6770

6871
verify(notificationService).processInboundEvent(eq(payload));
6972
verify(callbackDeliveryService).submitOutboundPcrEvents(payload, documentId);
73+
assertThat(result).isEqualTo(expectedPayload);
7074
}
7175

7276
@Test

0 commit comments

Comments
 (0)