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 DelegatedAccess entity #37

Merged
merged 4 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,20 @@
package de.adorsys.ledgers.baam.db.domain;

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

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class DelegatedAccess extends BankAccountAccess {

private DelegatedAccessType delegatedType;

public DelegatedAccess() {
super();
}

}


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

/**
* Enum representing different types of Power of Attorney.
*/
public enum DelegatedAccessType {
GENERAL,
LIMITED,
DURABLE,
SPRINGING
}

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

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

import java.util.List;

@Repository
public interface DelegatedAccessRepository extends JpaRepository<DelegatedAccess, String> {

List<DelegatedAccess> findByAccountId(String accountId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package de.adorsys.ledgers.baam.db.repository;

import com.github.springtestdbunit.DbUnitTestExecutionListener;
import de.adorsys.ledgers.baam.db.domain.DelegatedAccess;
import de.adorsys.ledgers.baam.db.domain.DelegatedAccessType;
import de.adorsys.ledgers.baam.db.test.BaamRepositoryApplication;
import org.junit.jupiter.api.BeforeEach;
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.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = BaamRepositoryApplication.class)

@ExtendWith(SpringExtension.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class,
DbUnitTestExecutionListener.class})
class DelegatedAccessRepositoryTest {

@Autowired
private DelegatedAccessRepository delegatedAccessRepository;

private DelegatedAccess delegatedAccess;

@BeforeEach
void setUp() {
// Create a valid DelegatedAccess instance
delegatedAccess = new DelegatedAccess();
delegatedAccess.setId("1");
delegatedAccess.setAccountId("1");
delegatedAccess.setDelegatedType(DelegatedAccessType.GENERAL);
delegatedAccess.setAccountId("accountId123");
}

@Test
void testSaveDelegatedAccess() {
// Save DelegatedAccess and verify it was saved
DelegatedAccess savedDelegatedAccess = delegatedAccessRepository.save(delegatedAccess);
assertNotNull(savedDelegatedAccess.getId(), "Saved DelegatedAccess should have an ID");
assertEquals(DelegatedAccessType.GENERAL, savedDelegatedAccess.getDelegatedType(), "DelegatedAccess type should be GENERAL");
}

@Test
void testFindDelegatedAccessById() {
// Save DelegatedAccess and retrieve it by ID
DelegatedAccess savedDelegatedAccess = delegatedAccessRepository.save(delegatedAccess);
Optional<DelegatedAccess> foundDelegatedAccess = delegatedAccessRepository.findById(savedDelegatedAccess.getId());

assertTrue(foundDelegatedAccess.isPresent(), "DelegatedAccess should be found by ID");
}

@Test
void testFindDelegatedAccessByAccountId() {
// Save DelegatedAccess and retrieve by account ID
delegatedAccessRepository.save(delegatedAccess);
List<DelegatedAccess> foundDelegatedAccess = delegatedAccessRepository.findByAccountId("accountId123");

assertEquals(1, foundDelegatedAccess.size(), "There should be one DelegatedAccess for account 'accountId123'");
}
}
Loading