Search in sources :

Example 1 with CreateConsentRequest

use of net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest in project styx by petafuel.

the class BerlinGroupRequestFactoryTest method testAISConsentCreation.

@Test
void testAISConsentCreation() {
    UUID uuid = UUID.randomUUID();
    ThreadContext.put("requestUUID", uuid.toString());
    BerlinGroupRequestProvider berlinGroupRequestProvider = new BerlinGroupRequestProvider();
    AISRequestFactory requestFactory = new AISRequestFactory();
    XS2AFactoryInput factoryInput = new XS2AFactoryInput();
    Consent consent = new Consent();
    consent.setxRequestId(uuid);
    factoryInput.setConsent(consent);
    AISRequest berlinGroupAccountList = requestFactory.create(berlinGroupRequestProvider.consentCreation(), factoryInput);
    Assertions.assertTrue(berlinGroupAccountList instanceof CreateConsentRequest);
    Assertions.assertNotNull(berlinGroupAccountList.getTppRedirectUri());
    Assertions.assertTrue(berlinGroupAccountList.getTppRedirectUri().contains(uuid.toString()));
    Assertions.assertTrue(berlinGroupAccountList.getTppRedirectUri().contains(RealmParameter.OK.name().toLowerCase()));
    Assertions.assertNotNull(berlinGroupAccountList.getTppNokRedirectUri());
    Assertions.assertTrue(berlinGroupAccountList.getTppNokRedirectUri().contains(uuid.toString()));
    Assertions.assertTrue(berlinGroupAccountList.getTppNokRedirectUri().contains(RealmParameter.FAILED.name().toLowerCase()));
}
Also used : Consent(net.petafuel.styx.core.xs2a.entities.Consent) BerlinGroupRequestProvider(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.BerlinGroupRequestProvider) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) UUID(java.util.UUID) CreateConsentRequest(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest) Test(org.junit.jupiter.api.Test)

Example 2 with CreateConsentRequest

use of net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest in project styx by petafuel.

the class AISRequestFactory method create.

@Override
public AISRequest create(Class<? extends AISRequest> providedRequest, XS2AFactoryInput factoryInput) {
    try {
        Constructor<? extends AISRequest> constructor = providedRequest.getConstructor(Consent.class, String.class, String.class, String.class);
        AISRequest aisRequest = constructor.newInstance(factoryInput.getConsent(), factoryInput.getConsentId(), factoryInput.getAccountId(), factoryInput.getTransactionId());
        if (factoryInput.getAuthorisationId() != null) {
            aisRequest.setAuthorisationId(factoryInput.getAuthorisationId());
        }
        aisRequest.setPsu(factoryInput.getPsu());
        aisRequest.setBookingStatus(factoryInput.getBookingStatus());
        aisRequest.setDateFrom(factoryInput.getDateFrom());
        aisRequest.setDateTo(factoryInput.getDateTo());
        aisRequest.setWithBalance(factoryInput.getWithBalance());
        aisRequest.setEntryReferenceFrom(factoryInput.getEntryReferenceFrom());
        aisRequest.setDeltaList(factoryInput.getDeltaList());
        if (aisRequest instanceof CreateConsentRequest) {
            aisRequest.setTppRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.CONSENT, RealmParameter.OK, ThreadContext.get("requestUUID")));
            aisRequest.setTppNokRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.PAYMENT, RealmParameter.FAILED, ThreadContext.get("requestUUID")));
        }
        return aisRequest;
    } catch (NoSuchMethodException e) {
        throw new XS2AFactoryException(MessageFormat.format("No viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new XS2AFactoryException(MessageFormat.format("Unable to access constructor for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InstantiationException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request class is abstract, no viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InvocationTargetException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request constructor threw an exception for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new XS2AFactoryException(MessageFormat.format("The constructor signature was invalid for this Factory for request={0} error={1}", providedRequest, e.getMessage()), e);
    }
}
Also used : XS2AFactoryException(net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) CreateConsentRequest(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)2 CreateConsentRequest (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UUID (java.util.UUID)1 Consent (net.petafuel.styx.core.xs2a.entities.Consent)1 XS2AFactoryException (net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException)1 BerlinGroupRequestProvider (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.BerlinGroupRequestProvider)1 Test (org.junit.jupiter.api.Test)1