Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: created and tested third party access entity #32

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.adorsys.ledgers.baam.db.domain;

/**
* Enum representing different types of consents in the context of open banking.
* These consents define the scope of access granted to third-party service providers.
*/
public enum ConsentType {

/*
* The need to implement Other Open Banking Services may call for the creation of more ConsentTypes
*/

/**
* Consent allowing the third party to access account information such as
* balances, transaction histories, and account details without modifying them.
* This is typically used by Account Information Service Providers (AISP).
*/
ACCOUNT_INFORMATION_CONSENT,

/**
* Consent allowing the third party to initiate payments from the account
* on behalf of the account holder. This is typically used by Payment
* Initiation Service Providers (PISP).
*/
PAYMENT_INITIATION_CONSENT,

/**
* Consent allowing the third party to verify whether the account has
* sufficient funds for a particular transaction. No additional account
* information is provided beyond the confirmation of funds.
*/
CONFIRMATION_OF_FUNDS_CONSENT

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "third_party_access")
public class ThirdPartyAccess extends BankAccountAccess {

@Column(name = "consent_type")
@Enumerated(EnumType.STRING)
private ConsentType consentType;

@Column(name = "expiration_date")
private LocalDateTime expirationDate;

@Column(name = "max_transaction_amount")
private Double maxTransactionAmount;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.adorsys.ledgers.baam.db.repository;

import de.adorsys.ledgers.baam.db.domain.ThirdPartyAccess;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ThirdPartyAccessRepository extends JpaRepository<ThirdPartyAccess, String> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.adorsys.ledgers.baam.db.repository;

import com.github.springtestdbunit.DbUnitTestExecutionListener;
import de.adorsys.ledgers.baam.db.domain.AccessStatus;
import de.adorsys.ledgers.baam.db.domain.ConsentType;
import de.adorsys.ledgers.baam.db.domain.ThirdPartyAccess;
import de.adorsys.ledgers.baam.db.test.BaamRepositoryApplication;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest(classes = BaamRepositoryApplication.class)
@ExtendWith(SpringExtension.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class,
DbUnitTestExecutionListener.class})
public class ThirdPartyAccessRepositoryIT {

@Autowired
private ThirdPartyAccessRepository thirdPartyAccessRepository;

@Test
void test_createThirdPartyAccess_ok() {
// Given
thirdPartyAccessRepository.deleteAll(); // Clean up any existing records

ThirdPartyAccess thirdPartyAccess = new ThirdPartyAccess();
thirdPartyAccess.setId("1");
thirdPartyAccess.setAccountId("100L");
thirdPartyAccess.setEntityId("300L");
thirdPartyAccess.setConsentType(ConsentType.PAYMENT_INITIATION_CONSENT);
thirdPartyAccess.setExpirationDate(LocalDateTime.now().plusDays(90));
thirdPartyAccess.setMaxTransactionAmount(1000.00);
thirdPartyAccess.setStatus(AccessStatus.ACTIVE);

// When
ThirdPartyAccess savedAccess = thirdPartyAccessRepository.save(thirdPartyAccess);

// Retrieve the saved object
ThirdPartyAccess result = thirdPartyAccessRepository.findById(savedAccess.getId()).orElse(null);

// Then
assertNotNull(result);
assertEquals("100L", result.getAccountId());
assertEquals(ConsentType.PAYMENT_INITIATION_CONSENT, result.getConsentType());
assertEquals(1000.00, result.getMaxTransactionAmount());
}
}
Loading