use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiControllerIT method pollEvents_ackExistingEvent_errorExistingEvent_requestNone.
@Test
public void pollEvents_ackExistingEvent_errorExistingEvent_requestNone() {
OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(0).ack(Collections.singletonList("jti1")).setErrs(Collections.singletonMap("jti2", new OBEventPolling1SetErrs().err("err1").description("Error")));
FREventNotification frEventNotification1 = FREventNotification.builder().jti("jti1").signedJwt("e23239709rdg790").tppId(tpp.getId()).build();
frPendingEventsRepository.save(frEventNotification1);
FREventNotification frEventNotification2 = FREventNotification.builder().jti("jti2").signedJwt("o78o7tefkwjg").tppId(tpp.getId()).build();
frPendingEventsRepository.save(frEventNotification2);
// When
HttpResponse<OBEventPollingResponse1> response = Unirest.post(BASE_URL + port + RESOURCE_URI).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventPolling).asObject(OBEventPollingResponse1.class);
log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
// Then
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getBody().getSets().isEmpty()).isTrue();
// Check acknowledged event is deleted and errored event is stored with error message
assertThat(frPendingEventsRepository.findByTppIdAndJti(tpp.getId(), frEventNotification1.getJti()).isEmpty()).isTrue();
assertThat(frPendingEventsRepository.findByTppIdAndJti(tpp.getId(), frEventNotification2.getJti()).orElseThrow(AssertionError::new).getErrors().getError()).isEqualTo("err1");
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method fetchNewEvents_getAll.
@Test
public void fetchNewEvents_getAll() throws Exception {
// Given
final FREventNotification existingNotification1 = FREventNotification.builder().id("1").jti("11111").signedJwt("test111").build();
final FREventNotification existingNotification2 = FREventNotification.builder().id("2").jti("22222").signedJwt("test222").build();
when(mockRepo.findByTppId(eq(TPP_ID))).thenReturn(ImmutableList.of(existingNotification1, existingNotification2));
// When
FREventPolling pollingRequest = FREventPolling.builder().maxEvents(100).returnImmediately(true).build();
Map<String, String> eventNotifications = eventPollingService.fetchNewEvents(pollingRequest, TPP_ID);
// Then
assertThat(eventNotifications.size()).isEqualTo(2);
assertThat(eventNotifications.get("11111")).isEqualTo("test111");
assertThat(eventNotifications.get("22222")).isEqualTo("test222");
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method recordTppEventErrors_notificationExists_addError.
@Test
public void recordTppEventErrors_notificationExists_addError() {
// Given
final FREventNotification existingNotification = FREventNotification.builder().id("1").jti("11111").errors(null).build();
FREventPolling pollingRequest = FREventPolling.builder().setErrs(Collections.singletonMap("11111", FREventPollingError.builder().error("err1").description("error msg").build())).build();
when(mockRepo.findByTppIdAndJti(any(), any())).thenReturn(Optional.of(existingNotification));
// When
eventPollingService.recordTppEventErrors(pollingRequest, TPP_ID);
// Then
verify(mockRepo, times(1)).save(any());
assertThat(existingNotification.getErrors().getError()).isEqualTo("err1");
assertThat(existingNotification.getErrors().getDescription()).isEqualTo("error msg");
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class EventNotificationService method notifyToEventSubscription.
private void notifyToEventSubscription(Tpp tpp, FREventSubscription eventSubscription, FREventNotification eventNotification, EventSubject eventSubject, EventType eventType) {
log.debug("Found event subscription {} for the PISP Id: {}", eventSubscription, tpp.getId());
FREventSubscriptionData eventSubscription1Data = eventSubscription.getEventSubscription();
List<String> eventTypesForTpp = eventSubscription1Data.getEventTypes();
// Check event type filter
if (eventTypesForTpp != null && eventTypesForTpp.stream().noneMatch(e -> e.equals(eventType.getEventName()))) {
log.debug("TPP {} has subscribed to event types: {} but this event is type: {}", tpp.getId(), eventTypesForTpp, eventType.getEventName());
return;
}
String callbackUrl = eventSubscription.getEventSubscription().getCallbackUrl();
if (!StringUtils.isEmpty(callbackUrl)) {
log.debug("Found event subscription callback URL for the PISP Id: {}", tpp.getId());
try {
doCallback(tpp, callbackUrl, eventNotification, eventSubject);
} catch (CallbackFailedException e) {
// Save failed attempt so it can be polled later
log.warn("Callback to event subscription callback URL: {} failed so saving event for future polling", callbackUrl);
aggregatedPollingService.createPendingEventNotification(eventNotification);
}
} else {
// No callback URL but TPP has an event subscription so save for polling
aggregatedPollingService.createPendingEventNotification(eventNotification);
log.info("Created a pending notification that can be polled by the TPP for payment id: '{}' for PISP: {}", eventSubject.getId(), tpp.getId());
}
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class SignedJwtEventBuilderTest method buildClaimsForInternationalStandingOrder_validJwtClaimsBuilt.
@Test
public void buildClaimsForInternationalStandingOrder_validJwtClaimsBuilt() {
// Given
EventSubject subject = getEventSubject("PISOC_123", "v3.1", "international-standing-order");
// When
FREventNotification eventNotification = signedJwtEventBuilder.build(TPP, subject, EventType.RESOURCE_UPDATE_EVENT);
// Then
assertThat(eventNotification.getSignedJwt()).isEqualTo(FAKE_SIGNED_JWT);
areClaimsValidForConsentId(subject.getId(), "/v3.1/international-standing-orders", "international-standing-order", "v3.1");
}
Aggregations