use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiControllerIT method pollEvents_twoEvents_allRequested.
@Test
public void pollEvents_twoEvents_allRequested() {
// Given
OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(// All
null).returnImmediately(true);
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().isMoreAvailable()).isFalse();
assertThat(response.getBody().getSets().size()).isEqualTo(2);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method fetchNewEvents_excludeEventsWithErrorsFromResults.
@Test
public void fetchNewEvents_excludeEventsWithErrorsFromResults() throws Exception {
// Given
final FREventNotification existingNotificationWithoutError = FREventNotification.builder().id("1").jti("11111").signedJwt("test111").build();
final FREventNotification existingNotificationWithError = FREventNotification.builder().id("2").jti("22222").signedJwt("test222").errors(FREventPollingError.builder().error("err1").description("error").build()).build();
when(mockRepo.findByTppId(eq(TPP_ID))).thenReturn(ImmutableList.of(existingNotificationWithoutError, existingNotificationWithError));
// When
FREventPolling pollingRequest = FREventPolling.builder().maxEvents(// Do not restrict
null).returnImmediately(true).build();
Map<String, String> eventNotifications = eventPollingService.fetchNewEvents(pollingRequest, TPP_ID);
// Then
assertThat(eventNotifications.size()).isEqualTo(1);
assertThat(eventNotifications.get("11111")).isEqualTo("test111");
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class DataEventsApiController method updateEvents.
/**
* Update events
* @param eventsToUpdate list of {@link FREventNotification} to update
* @param frDataEvent the entity body {@link FRDataEvent}
* @throws {@link OBErrorResponseException}
*/
private void updateEvents(List<FREventNotification> eventsToUpdate, FRDataEvent frDataEvent) throws OBErrorResponseException {
try {
frDataEvent.getObEventNotification2List().forEach(fde -> {
Optional<FREventNotification> optionalFREventNotification = eventsToUpdate.stream().filter(e -> e.getJti().equals(fde.getJti())).findFirst();
if (optionalFREventNotification.isEmpty()) {
log.error("Error updating the events, the jti set in the request not match with any existing event");
throw new RuntimeException(new OBErrorResponseException(OBRIErrorType.DATA_INVALID_REQUEST.getHttpStatus(), OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.DATA_INVALID_REQUEST.toOBError1("The jti set in the request not match with any existing event")));
}
try {
FREventNotification frEventNotification = optionalFREventNotification.get();
frEventNotification.setSignedJwt(signPayload(fde));
frPendingEventsRepository.save(frEventNotification);
} catch (OBErrorException obErrorException) {
throw new RuntimeException(obErrorException);
}
});
} catch (RuntimeException exception) {
throw handleError(exception);
}
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class DataEventsApiController method createEvents.
/**
* Create new events
* @param frDataEvent the entity body {@link FRDataEvent}
*/
private void createEvents(FRDataEvent frDataEvent) {
frDataEvent.getObEventNotification2List().forEach(e -> {
try {
FREventNotification frEventNotification = FREventNotification.builder().jti(UUID.randomUUID().toString()).signedJwt(signPayload(e)).tppId(frDataEvent.getTppId()).build();
log.debug("Create event notification {}", frEventNotification);
frPendingEventsRepository.save(frEventNotification);
frDataEvent.setJti(frEventNotification.getJti());
} catch (OBErrorException obErrorException) {
throw new RuntimeException(obErrorException);
}
});
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiControllerIT method pollEvents_twoEvents_twoRequested.
@Test
public void pollEvents_twoEvents_twoRequested() {
// Given
OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(2);
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().isMoreAvailable()).isFalse();
assertThat(response.getBody().getSets().size()).isEqualTo(2);
}
Aggregations