diff --git a/application/src/main/java/com/cdx/bas/application/transaction/TransactionMapper.java b/application/src/main/java/com/cdx/bas/application/transaction/TransactionMapper.java index 492af5dd..bbfcae23 100644 --- a/application/src/main/java/com/cdx/bas/application/transaction/TransactionMapper.java +++ b/application/src/main/java/com/cdx/bas/application/transaction/TransactionMapper.java @@ -27,8 +27,13 @@ public class TransactionMapper implements DtoEntityMapper expectedTransaction = Optional.of(new Transaction(1L, 1L, 2L, - new BigDecimal("1600.00"), "EUR", CREDIT, COMPLETED, - expectedInstant, - "transaction 1", Map.of("sender_amount_before", "2000", "receiver_amount_before", "0", "sender_amount_after", "400", "receiver_amount_after", "1600"))); + Optional expectedTransaction = Optional.of(Transaction.builder() + .id(1L) + .senderAccountId(1L) + .receiverAccountId(2L) + .amount(new BigDecimal("1600.00")) + .currency("EUR") + .type(CREDIT) + .status(COMPLETED) + .date(expectedInstant) + .label("transaction 1") + .metadata(Map.of("sender_amount_before", "2000", "receiver_amount_before", "0", "sender_amount_after", "400", "receiver_amount_after", "1600")) + .build()); Optional actualTransaction = transactionRepository.findById(1); // Assert @@ -56,7 +64,20 @@ public void findUnprocessedTransactions_shouldFindEveryUnprocessedTransactions() Queue actualUnprocessedTransactions = transactionRepository.findUnprocessedTransactions(); Queue expectedUnprocessedTransactions = new PriorityQueue<>(); - expectedUnprocessedTransactions.add(new Transaction(5L, 2L, 1L, new BigDecimal("600.99"), "EUR", CREDIT, UNPROCESSED, Instant.parse("2024-11-06T17:00:00+00:00"), "transaction 5", new HashMap<>())); + expectedUnprocessedTransactions.add(Transaction.builder() + .id(5L) + .senderAccountId(2L) + .receiverAccountId(1L) + .amount(new BigDecimal("600.99")) + .currency("EUR") + .type(CREDIT) + .status(UNPROCESSED) + .date(Instant.parse("2024-11-06T17:00:00+00:00")) + .label("transaction 5") + .metadata(new HashMap<>()) + .build()); + + //TODO expectedUnprocessedTransactions.add(new Transaction(6L, 1L, 7L, new BigDecimal("2000.00"), "EUR", DEBIT, UNPROCESSED, Instant.parse("2024-11-06T17:30:00+00:00"), "transaction 6", new HashMap<>())); expectedUnprocessedTransactions.add(new Transaction(7L, 3L, 1L, new BigDecimal("1000.00"), "EUR", CREDIT, UNPROCESSED, Instant.parse("2024-12-06T17:00:00+00:00"), "transaction 7", new HashMap<>())); expectedUnprocessedTransactions.add(new Transaction(8L, 4L, 2L, new BigDecimal("300.80"), "EUR", DEBIT, UNPROCESSED, Instant.parse("2024-12-06T18:00:00+00:00"), "transaction 8", new HashMap<>())); diff --git a/domain/pom.xml b/domain/pom.xml index d764f8fa..7fc2edd9 100644 --- a/domain/pom.xml +++ b/domain/pom.xml @@ -47,6 +47,12 @@ io.quarkus quarkus-hibernate-validator + + org.projectlombok + lombok + 1.18.30 + provided + diff --git a/domain/src/main/java/com/cdx/bas/domain/transaction/Transaction.java b/domain/src/main/java/com/cdx/bas/domain/transaction/Transaction.java index 38f11309..fc5ad4de 100644 --- a/domain/src/main/java/com/cdx/bas/domain/transaction/Transaction.java +++ b/domain/src/main/java/com/cdx/bas/domain/transaction/Transaction.java @@ -3,6 +3,8 @@ import com.cdx.bas.domain.validator.ValidCurrency; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; +import lombok.Builder; +import lombok.Data; import java.math.BigDecimal; import java.time.Instant; @@ -10,6 +12,8 @@ import java.util.Map; import java.util.Objects; +@Data +@Builder public class Transaction implements Comparable { @NotNull(message = "id must not be null.") @@ -43,115 +47,9 @@ public class Transaction implements Comparable { private Map metadata = new HashMap<>(); - public Transaction() { - super(); - } - - public Transaction(long accountId, String currency, BigDecimal amount, TransactionType type) { - this.id = accountId; - this.amount = amount; - this.currency = currency; - this.type = type; - this.status = TransactionStatus.UNPROCESSED; - this.date = Instant.now(); - } - - public Transaction(Long id, Long senderAccountId, Long receiverAccountId, BigDecimal amount, String currency, TransactionType type, TransactionStatus status, Instant date, String label, Map metadata) { - this.id = id; - this.senderAccountId = senderAccountId; - this.receiverAccountId = receiverAccountId; - this.amount = amount; - this.currency = currency; - this.type = type; - this.status = status; - this.date = date; - this.label = label; - this.metadata = metadata; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getSenderAccountId() { - return senderAccountId; - } - - public void setSenderAccountId(Long senderAccountId) { - this.senderAccountId = senderAccountId; - } - - public Long getReceiverAccountId() { - return receiverAccountId; - } - - public void setReceiverAccountId(Long receiverAccountId) { - this.receiverAccountId = receiverAccountId; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public TransactionType getType() { - return type; - } - - public void setType(TransactionType type) { - this.type = type; - } - - public TransactionStatus getStatus() { - return status; - } - - public void setStatus(TransactionStatus status) { - this.status = status; - } - - public Instant getDate() { - return date; - } - - public void setDate(Instant date) { - this.date = date; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - @Override - public int compareTo(Transaction transactionToCompar) { - return this.getDate().compareTo(transactionToCompar.getDate()); + public int compareTo(Transaction transactionToCompare) { + return this.getDate().compareTo(transactionToCompare.getDate()); } @Override diff --git a/pom.xml b/pom.xml index 0196f232..fd5b4985 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,7 @@ 3.1.5 3.11.0 3.25.3 + 1.18.30 @@ -92,6 +93,11 @@ quarkus-test-h2 ${quarkus.platform.version} + + org.projectlombok + lombok + 1.18.30 +