Skip to content

Commit

Permalink
Merge pull request #38 from ADORSYS-GIS/TellerAccess
Browse files Browse the repository at this point in the history
feat: Create TellerAccess entity and add unit tests
  • Loading branch information
yvanhenang authored Oct 8, 2024
2 parents b3bc4dd + 6f474b3 commit d594355
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TellerAccess extends BankAccountAccess {

private double dailyLimit;

}
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.TellerAccess;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TellerAccessRepository extends JpaRepository<TellerAccess, String> {

}
Original file line number Diff line number Diff line change
@@ -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<TellerAccess> retrievedTellerAccess = tellerAccessRepository.findById("123");
assertTrue(retrievedTellerAccess.isPresent());
assertEquals(3000.0, retrievedTellerAccess.get().getDailyLimit());
}
}

0 comments on commit d594355

Please sign in to comment.