From 39834c309cd7ed74cde246b12fa19531ba52d90b Mon Sep 17 00:00:00 2001 From: yvanhenang Date: Wed, 2 Oct 2024 17:32:47 +0100 Subject: [PATCH 1/3] feat: Create TellerAccess entity and add unit tests --- .../ledgers/baam/db/domain/TellerAccess.java | 42 ++++++++++ .../db/repository/TellerAccessRepository.java | 13 +++ .../repository/TellerAccessRepositoryIT.java | 81 +++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java create mode 100644 ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java create mode 100644 ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java new file mode 100644 index 000000000..371bb726a --- /dev/null +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java @@ -0,0 +1,42 @@ +package de.adorsys.ledgers.baam.db.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.persistence.*; +import java.util.Date; +import java.util.UUID; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TellerAccess { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private UUID id; + + private String name; + private String tellerId; + + + @Enumerated(EnumType.STRING) + private AccessStatus status; + + private double dailyLimit; + + @Temporal(TemporalType.TIMESTAMP) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + private Date lastModifiedDate; + + + private String accessType = "TELLER_ACCESS"; +} diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java new file mode 100644 index 000000000..88a9ea986 --- /dev/null +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java @@ -0,0 +1,13 @@ +package de.adorsys.ledgers.baam.db.repository; + + +import de.adorsys.ledgers.baam.db.domain.TellerAccess; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; + +@Repository +public interface TellerAccessRepository extends JpaRepository { + +} diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java new file mode 100644 index 000000000..1196670e1 --- /dev/null +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java @@ -0,0 +1,81 @@ +package de.adorsys.ledgers.baam.db.repository; + +import de.adorsys.ledgers.baam.db.domain.AccessStatus; +import de.adorsys.ledgers.baam.db.domain.TellerAccess; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Date; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +class TellerAccessTest { + + private TellerAccess tellerAccess; + + @BeforeEach + void setUp() { + tellerAccess = new TellerAccess(); + } + + @Test + void testTellerAccessCreation() { + // Create UUID + UUID id = UUID.randomUUID(); + String tellerName = "John Doe"; + String tellerId = "TELLER123"; + AccessStatus status = AccessStatus.ACTIVE; + double dailyLimit = 5000.0; + Date createdDate = new Date(); + Date lastModifiedDate = new Date(); + + // Set values using constructor + TellerAccess tellerAccess = new TellerAccess(id, tellerName, tellerId, status, dailyLimit, createdDate, lastModifiedDate, "TELLER_ACCESS"); + + // Assert that the values have been set correctly + assertEquals(id, tellerAccess.getId()); + assertEquals(tellerName, tellerAccess.getName()); + assertEquals(tellerId, tellerAccess.getTellerId()); + assertEquals(status, tellerAccess.getStatus()); + assertEquals(dailyLimit, tellerAccess.getDailyLimit()); + assertEquals(createdDate, tellerAccess.getCreatedDate()); + assertEquals(lastModifiedDate, tellerAccess.getLastModifiedDate()); + assertEquals("TELLER_ACCESS", tellerAccess.getAccessType()); + } + + @Test + void testStatusUpdate() { + // Initial status + tellerAccess.setStatus(AccessStatus.ACTIVE); + assertEquals(AccessStatus.ACTIVE, tellerAccess.getStatus()); + + // Change status to SUSPENDED + tellerAccess.setStatus(AccessStatus.SUSPENDED); + assertEquals(AccessStatus.SUSPENDED, tellerAccess.getStatus()); + } + + @Test + void testSetDailyLimit() { + tellerAccess.setDailyLimit(2000.0); + assertEquals(2000.0, tellerAccess.getDailyLimit()); + + // Update daily limit + tellerAccess.setDailyLimit(3000.0); + assertEquals(3000.0, tellerAccess.getDailyLimit()); + } + + @Test + void testSetCreatedDate() { + Date now = new Date(); + tellerAccess.setCreatedDate(now); + assertEquals(now, tellerAccess.getCreatedDate()); + } + + @Test + void testSetLastModifiedDate() { + Date now = new Date(); + tellerAccess.setLastModifiedDate(now); + assertEquals(now, tellerAccess.getLastModifiedDate()); + } +} From 7ef63c565131ca075c88ef952bb5ba82c8d7ab72 Mon Sep 17 00:00:00 2001 From: yvanhenang Date: Thu, 3 Oct 2024 01:48:32 +0100 Subject: [PATCH 2/3] Update TellerAccess entity and its tests --- .../ledgers/baam/db/domain/TellerAccess.java | 4 +- .../repository/TellerAccessRepositoryIT.java | 113 ++++++++++++------ 2 files changed, 75 insertions(+), 42 deletions(-) diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java index 371bb726a..93e5a907a 100644 --- a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java @@ -16,7 +16,7 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class TellerAccess { +public class TellerAccess { @Id @GeneratedValue(strategy = GenerationType.UUID) @@ -25,7 +25,6 @@ public class TellerAccess { private String name; private String tellerId; - @Enumerated(EnumType.STRING) private AccessStatus status; @@ -37,6 +36,5 @@ public class TellerAccess { @Temporal(TemporalType.TIMESTAMP) private Date lastModifiedDate; - private String accessType = "TELLER_ACCESS"; } diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java index 1196670e1..5e6ed2341 100644 --- a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java @@ -1,16 +1,34 @@ 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.TellerAccess; +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.Date; +import java.util.Optional; import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; -class TellerAccessTest { +@SpringBootTest(classes = BaamRepositoryApplication.class) +@ExtendWith(SpringExtension.class) +@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, + TransactionalTestExecutionListener.class, + DbUnitTestExecutionListener.class}) +class TellerAccessRepositoryTest { + + @Autowired + private TellerAccessRepository tellerAccessRepository; private TellerAccess tellerAccess; @@ -20,9 +38,8 @@ void setUp() { } @Test - void testTellerAccessCreation() { - // Create UUID - UUID id = UUID.randomUUID(); + void testTellerAccessCreationWithAutoGeneratedUUID() { + // Create and set up a new TellerAccess entity without setting the UUID String tellerName = "John Doe"; String tellerId = "TELLER123"; AccessStatus status = AccessStatus.ACTIVE; @@ -30,52 +47,70 @@ void testTellerAccessCreation() { Date createdDate = new Date(); Date lastModifiedDate = new Date(); - // Set values using constructor - TellerAccess tellerAccess = new TellerAccess(id, tellerName, tellerId, status, dailyLimit, createdDate, lastModifiedDate, "TELLER_ACCESS"); - - // Assert that the values have been set correctly - assertEquals(id, tellerAccess.getId()); - assertEquals(tellerName, tellerAccess.getName()); - assertEquals(tellerId, tellerAccess.getTellerId()); - assertEquals(status, tellerAccess.getStatus()); - assertEquals(dailyLimit, tellerAccess.getDailyLimit()); - assertEquals(createdDate, tellerAccess.getCreatedDate()); - assertEquals(lastModifiedDate, tellerAccess.getLastModifiedDate()); - assertEquals("TELLER_ACCESS", tellerAccess.getAccessType()); + // Set values using constructor, but UUID will be autogenerated + TellerAccess newTellerAccess = new TellerAccess(null, tellerName, tellerId, status, dailyLimit, createdDate, lastModifiedDate, "TELLER_ACCESS"); + + // Save to repository (persist) + TellerAccess savedTellerAccess = tellerAccessRepository.save(newTellerAccess); + + // Check that a UUID was generated after saving + assertNotNull(savedTellerAccess.getId()); // Assert that the UUID was generated + assertEquals(tellerName, savedTellerAccess.getName()); + assertEquals(tellerId, savedTellerAccess.getTellerId()); + assertEquals(status, savedTellerAccess.getStatus()); + assertEquals(dailyLimit, savedTellerAccess.getDailyLimit()); + + // Check dates, but avoid exact matches due to timing issues + assertNotNull(savedTellerAccess.getCreatedDate()); + assertNotNull(savedTellerAccess.getLastModifiedDate()); + + assertEquals("TELLER_ACCESS", savedTellerAccess.getAccessType()); } + @Test - void testStatusUpdate() { - // Initial status + void testStatusUpdateInDatabase() { + // Create and save an entity + tellerAccess.setId(UUID.randomUUID()); + tellerAccess.setName("Jane Smith"); + tellerAccess.setTellerId("TELLER456"); tellerAccess.setStatus(AccessStatus.ACTIVE); - assertEquals(AccessStatus.ACTIVE, tellerAccess.getStatus()); + tellerAccess.setDailyLimit(1000.0); + tellerAccess.setCreatedDate(new Date()); + tellerAccess.setLastModifiedDate(new Date()); + + TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); + + // Update status to SUSPENDED + savedTellerAccess.setStatus(AccessStatus.SUSPENDED); + TellerAccess updatedTellerAccess = tellerAccessRepository.save(savedTellerAccess); - // Change status to SUSPENDED - tellerAccess.setStatus(AccessStatus.SUSPENDED); - assertEquals(AccessStatus.SUSPENDED, tellerAccess.getStatus()); + // Retrieve from DB and verify the status change + Optional retrievedTellerAccess = tellerAccessRepository.findById(updatedTellerAccess.getId()); + assertTrue(retrievedTellerAccess.isPresent()); + assertEquals(AccessStatus.SUSPENDED, retrievedTellerAccess.get().getStatus()); } @Test - void testSetDailyLimit() { + void testSetDailyLimitInDatabase() { + // Create and save an entity + tellerAccess.setId(UUID.randomUUID()); + tellerAccess.setName("Paul Walker"); + tellerAccess.setTellerId("TELLER789"); + tellerAccess.setStatus(AccessStatus.ACTIVE); tellerAccess.setDailyLimit(2000.0); - assertEquals(2000.0, tellerAccess.getDailyLimit()); + tellerAccess.setCreatedDate(new Date()); + tellerAccess.setLastModifiedDate(new Date()); - // Update daily limit - tellerAccess.setDailyLimit(3000.0); - assertEquals(3000.0, tellerAccess.getDailyLimit()); - } + TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); - @Test - void testSetCreatedDate() { - Date now = new Date(); - tellerAccess.setCreatedDate(now); - assertEquals(now, tellerAccess.getCreatedDate()); - } + // Update daily limit + savedTellerAccess.setDailyLimit(3000.0); + TellerAccess updatedTellerAccess = tellerAccessRepository.save(savedTellerAccess); - @Test - void testSetLastModifiedDate() { - Date now = new Date(); - tellerAccess.setLastModifiedDate(now); - assertEquals(now, tellerAccess.getLastModifiedDate()); + // Retrieve from DB and verify the daily limit change + Optional retrievedTellerAccess = tellerAccessRepository.findById(updatedTellerAccess.getId()); + assertTrue(retrievedTellerAccess.isPresent()); + assertEquals(3000.0, retrievedTellerAccess.get().getDailyLimit()); } } From 6f474b3e98ec350964ec786fd1df1f6bca027e10 Mon Sep 17 00:00:00 2001 From: yvanhenang Date: Mon, 7 Oct 2024 14:24:55 +0100 Subject: [PATCH 3/3] Update TellerAccess --- .../ledgers/baam/db/domain/TellerAccess.java | 26 +--- .../db/repository/TellerAccessRepository.java | 4 +- .../repository/TellerAccessRepositoryIT.java | 116 ------------------ .../TellerAccessRepositoryTest.java | 61 +++++++++ 4 files changed, 63 insertions(+), 144 deletions(-) delete mode 100644 ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java create mode 100644 ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryTest.java diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java index 93e5a907a..07068d907 100644 --- a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TellerAccess.java @@ -1,40 +1,16 @@ package de.adorsys.ledgers.baam.db.domain; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import jakarta.persistence.*; -import java.util.Date; -import java.util.UUID; - @Entity @Data @NoArgsConstructor @AllArgsConstructor -public class TellerAccess { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - private UUID id; - - private String name; - private String tellerId; - - @Enumerated(EnumType.STRING) - private AccessStatus status; +public class TellerAccess extends BankAccountAccess { private double dailyLimit; - @Temporal(TemporalType.TIMESTAMP) - private Date createdDate; - - @Temporal(TemporalType.TIMESTAMP) - private Date lastModifiedDate; - - private String accessType = "TELLER_ACCESS"; } diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java index 88a9ea986..9f1977131 100644 --- a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/main/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepository.java @@ -5,9 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.UUID; - @Repository -public interface TellerAccessRepository extends JpaRepository { +public interface TellerAccessRepository extends JpaRepository { } diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java deleted file mode 100644 index 5e6ed2341..000000000 --- a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryIT.java +++ /dev/null @@ -1,116 +0,0 @@ -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.TellerAccess; -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.Date; -import java.util.Optional; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest(classes = BaamRepositoryApplication.class) -@ExtendWith(SpringExtension.class) -@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, - TransactionalTestExecutionListener.class, - DbUnitTestExecutionListener.class}) -class TellerAccessRepositoryTest { - - @Autowired - private TellerAccessRepository tellerAccessRepository; - - private TellerAccess tellerAccess; - - @BeforeEach - void setUp() { - tellerAccess = new TellerAccess(); - } - - @Test - void testTellerAccessCreationWithAutoGeneratedUUID() { - // Create and set up a new TellerAccess entity without setting the UUID - String tellerName = "John Doe"; - String tellerId = "TELLER123"; - AccessStatus status = AccessStatus.ACTIVE; - double dailyLimit = 5000.0; - Date createdDate = new Date(); - Date lastModifiedDate = new Date(); - - // Set values using constructor, but UUID will be autogenerated - TellerAccess newTellerAccess = new TellerAccess(null, tellerName, tellerId, status, dailyLimit, createdDate, lastModifiedDate, "TELLER_ACCESS"); - - // Save to repository (persist) - TellerAccess savedTellerAccess = tellerAccessRepository.save(newTellerAccess); - - // Check that a UUID was generated after saving - assertNotNull(savedTellerAccess.getId()); // Assert that the UUID was generated - assertEquals(tellerName, savedTellerAccess.getName()); - assertEquals(tellerId, savedTellerAccess.getTellerId()); - assertEquals(status, savedTellerAccess.getStatus()); - assertEquals(dailyLimit, savedTellerAccess.getDailyLimit()); - - // Check dates, but avoid exact matches due to timing issues - assertNotNull(savedTellerAccess.getCreatedDate()); - assertNotNull(savedTellerAccess.getLastModifiedDate()); - - assertEquals("TELLER_ACCESS", savedTellerAccess.getAccessType()); - } - - - @Test - void testStatusUpdateInDatabase() { - // Create and save an entity - tellerAccess.setId(UUID.randomUUID()); - tellerAccess.setName("Jane Smith"); - tellerAccess.setTellerId("TELLER456"); - tellerAccess.setStatus(AccessStatus.ACTIVE); - tellerAccess.setDailyLimit(1000.0); - tellerAccess.setCreatedDate(new Date()); - tellerAccess.setLastModifiedDate(new Date()); - - TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); - - // Update status to SUSPENDED - savedTellerAccess.setStatus(AccessStatus.SUSPENDED); - TellerAccess updatedTellerAccess = tellerAccessRepository.save(savedTellerAccess); - - // Retrieve from DB and verify the status change - Optional retrievedTellerAccess = tellerAccessRepository.findById(updatedTellerAccess.getId()); - assertTrue(retrievedTellerAccess.isPresent()); - assertEquals(AccessStatus.SUSPENDED, retrievedTellerAccess.get().getStatus()); - } - - @Test - void testSetDailyLimitInDatabase() { - // Create and save an entity - tellerAccess.setId(UUID.randomUUID()); - tellerAccess.setName("Paul Walker"); - tellerAccess.setTellerId("TELLER789"); - tellerAccess.setStatus(AccessStatus.ACTIVE); - tellerAccess.setDailyLimit(2000.0); - tellerAccess.setCreatedDate(new Date()); - tellerAccess.setLastModifiedDate(new Date()); - - TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); - - // Update daily limit - savedTellerAccess.setDailyLimit(3000.0); - TellerAccess updatedTellerAccess = tellerAccessRepository.save(savedTellerAccess); - - // Retrieve from DB and verify the daily limit change - Optional retrievedTellerAccess = tellerAccessRepository.findById(updatedTellerAccess.getId()); - assertTrue(retrievedTellerAccess.isPresent()); - assertEquals(3000.0, retrievedTellerAccess.get().getDailyLimit()); - } -} diff --git a/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryTest.java b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryTest.java new file mode 100644 index 000000000..5a14a3a17 --- /dev/null +++ b/ledgers-bank-account-access-management/ledgers-bank-account-access-repository/src/test/java/de/adorsys/ledgers/baam/db/repository/TellerAccessRepositoryTest.java @@ -0,0 +1,61 @@ +package de.adorsys.ledgers.baam.db.repository; + +import com.github.springtestdbunit.DbUnitTestExecutionListener; +import de.adorsys.ledgers.baam.db.domain.TellerAccess; +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.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest(classes = BaamRepositoryApplication.class) +@ExtendWith(SpringExtension.class) +@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, + TransactionalTestExecutionListener.class, + DbUnitTestExecutionListener.class}) +public class TellerAccessRepositoryTest { + + @Autowired + private TellerAccessRepository tellerAccessRepository; + + @Test + void testTellerAccessCreation() { + + TellerAccess tellerAccess = new TellerAccess(); + + tellerAccess.setId("123"); + + // Save to repository (persist) + TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); + savedTellerAccess.setId("456"); + assertNotEquals(savedTellerAccess.getId(), tellerAccess.getId()); + + } + + + @Test + void testSetDailyLimitInDatabase() { + // Create and save an entity + TellerAccess tellerAccess = new TellerAccess(); + tellerAccess.setDailyLimit(3000.0); + tellerAccess.setId("123"); + + TellerAccess savedTellerAccess = tellerAccessRepository.save(tellerAccess); + + // Update daily limit + savedTellerAccess.setDailyLimit(3000.0); + + // Retrieve from DB and verify the daily limit change + Optional retrievedTellerAccess = tellerAccessRepository.findById("123"); + assertTrue(retrievedTellerAccess.isPresent()); + assertEquals(3000.0, retrievedTellerAccess.get().getDailyLimit()); + } +}