Search in sources :

Example 16 with FREventNotification

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");
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBEventPollingResponse1(uk.org.openbanking.datamodel.event.OBEventPollingResponse1) OBEventPolling1(uk.org.openbanking.datamodel.event.OBEventPolling1) OBEventPolling1SetErrs(uk.org.openbanking.datamodel.event.OBEventPolling1SetErrs) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with FREventNotification

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");
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) FREventPolling(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling) Test(org.junit.Test)

Example 18 with FREventNotification

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");
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) FREventPolling(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling) Test(org.junit.Test)

Example 19 with FREventNotification

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());
    }
}
Also used : EventSubject(com.forgerock.openbanking.common.services.notification.EventSubject) EventType(com.forgerock.openbanking.common.services.notification.EventType) Tpp(com.forgerock.openbanking.model.Tpp) EventSubscriptionService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.EventSubscriptionService) FREventSubscriptionData(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData) DateTime(org.joda.time.DateTime) AggregatedPollingService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.AggregatedPollingService) CallBackCounterEntry(com.forgerock.openbanking.analytics.model.entries.callback.CallBackCounterEntry) CallBackResponseStatus(com.forgerock.openbanking.analytics.model.entries.callback.CallBackResponseStatus) FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription) CallbackUrlsService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.CallbackUrlsService) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) CallBackCountersKPIService(com.forgerock.openbanking.analytics.services.CallBackCountersKPIService) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) Optional(java.util.Optional) FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) FREventSubscriptionData(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData)

Example 20 with FREventNotification

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");
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) EventSubject(com.forgerock.openbanking.common.services.notification.EventSubject) Test(org.junit.Test)

Aggregations

FREventNotification (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification)21 Test (org.junit.Test)17 EventSubject (com.forgerock.openbanking.common.services.notification.EventSubject)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)6 OBEventPolling1 (uk.org.openbanking.datamodel.event.OBEventPolling1)6 OBEventPollingResponse1 (uk.org.openbanking.datamodel.event.OBEventPollingResponse1)6 FREventPolling (com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling)3 FRDataEvent (com.forgerock.openbanking.common.model.data.FRDataEvent)2 FREventSubscription (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription)2 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)2 Slf4j (lombok.extern.slf4j.Slf4j)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AMOpenBankingConfiguration (com.forgerock.openbanking.am.config.AMOpenBankingConfiguration)1 CallBackCounterEntry (com.forgerock.openbanking.analytics.model.entries.callback.CallBackCounterEntry)1 CallBackResponseStatus (com.forgerock.openbanking.analytics.model.entries.callback.CallBackResponseStatus)1 CallBackCountersKPIService (com.forgerock.openbanking.analytics.services.CallBackCountersKPIService)1 AggregatedPollingService (com.forgerock.openbanking.aspsp.rs.simulator.event.store.AggregatedPollingService)1 CallbackUrlsService (com.forgerock.openbanking.aspsp.rs.simulator.event.store.CallbackUrlsService)1