Skip to content

Commit

Permalink
Update TellerAccess entity and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanhenang committed Oct 3, 2024
1 parent 39834c3 commit 7ef63c5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TellerAccess {
public class TellerAccess {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
Expand All @@ -25,7 +25,6 @@ public class TellerAccess {
private String name;
private String tellerId;


@Enumerated(EnumType.STRING)
private AccessStatus status;

Expand All @@ -37,6 +36,5 @@ public class TellerAccess {
@Temporal(TemporalType.TIMESTAMP)
private Date lastModifiedDate;


private String accessType = "TELLER_ACCESS";
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,62 +38,79 @@ 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;
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());
// 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<TellerAccess> 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<TellerAccess> retrievedTellerAccess = tellerAccessRepository.findById(updatedTellerAccess.getId());
assertTrue(retrievedTellerAccess.isPresent());
assertEquals(3000.0, retrievedTellerAccess.get().getDailyLimit());
}
}

0 comments on commit 7ef63c5

Please sign in to comment.