From 9b101757cdb1072cb7e11c01b8e9bf8461b17422 Mon Sep 17 00:00:00 2001 From: Devin AI Date: Thu, 24 Sep 2026 14:51:28 +0000 Subject: [PATCH 1/3] feature(COG-1143): W0 smoke suite for deposit, withdraw, between-accounts and recipient transfer Adds a Testcontainers-backed AbstractIntegrationTest harness and MockMvc regression tests asserting persisted balances and ledger rows on Boot 1.5.4. Co-Authored-By: patrick.bradley --- .../com/userFront/MoneyMovementSmokeTest.java | 318 ++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java diff --git a/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java new file mode 100644 index 00000000..837607ee --- /dev/null +++ b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java @@ -0,0 +1,318 @@ +package com.userFront; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.web.servlet.MockMvc; + +import com.userFront.dao.PrimaryAccountDao; +import com.userFront.dao.PrimaryTransactionDao; +import com.userFront.dao.RecipientDao; +import com.userFront.dao.SavingsAccountDao; +import com.userFront.dao.SavingsTransactionDao; +import com.userFront.domain.PrimaryAccount; +import com.userFront.domain.PrimaryTransaction; +import com.userFront.domain.Recipient; +import com.userFront.domain.SavingsAccount; +import com.userFront.domain.SavingsTransaction; +import com.userFront.domain.User; +import com.userFront.domain.security.Role; +import com.userFront.domain.security.UserRole; +import com.userFront.service.UserService; + +/** + * Regression contract for money movement on Boot 1.5.4: deposit, withdraw, + * between-accounts transfer, the recipient lifecycle and recipient transfer. + * Asserts on the persisted rows, and records today's behaviour as-is. + */ +public class MoneyMovementSmokeTest extends AbstractIntegrationTest { + + private static final AtomicInteger SEQ = new AtomicInteger(); + + @Autowired + private MockMvc mockMvc; + + @Autowired + private UserService userService; + + @Autowired + private PrimaryAccountDao primaryAccountDao; + + @Autowired + private SavingsAccountDao savingsAccountDao; + + @Autowired + private PrimaryTransactionDao primaryTransactionDao; + + @Autowired + private SavingsTransactionDao savingsTransactionDao; + + @Autowired + private RecipientDao recipientDao; + + private String username; + + @Before + public void createUser() { + int n = SEQ.incrementAndGet(); + username = "smoke" + System.nanoTime() + n; + + User user = new User(); + user.setUsername(username); + user.setPassword("password"); + user.setFirstName("Smoke"); + user.setLastName("Test"); + user.setEmail(username + "@example.com"); + user.setPhone("5551234567"); + + Role role = new Role(); + role.setRoleId(1); + role.setName("ROLE_USER"); + + Set roles = new HashSet<>(); + roles.add(new UserRole(user, role)); + + userService.createUser(user, roles); + } + + @Test + public void depositCreditsPrimaryAccountAndWritesLedgerRow() throws Exception { + mockMvc.perform(post("/account/deposit").with(user(username)).param("accountType", "Primary").param("amount", + "250.00")).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/userFront")); + + assertEquals(0, new BigDecimal("250.00").compareTo(primaryBalance())); + + PrimaryTransaction transaction = onlyPrimaryTransaction(); + assertEquals("Deposit to Primary Account", transaction.getDescription()); + assertEquals("Account", transaction.getType()); + assertEquals("Finished", transaction.getStatus()); + assertEquals(250.00, transaction.getAmount(), 0.001); + assertEquals(0, new BigDecimal("250.00").compareTo(transaction.getAvailableBalance())); + } + + @Test + public void depositCreditsSavingsAccountAndWritesLedgerRow() throws Exception { + mockMvc.perform(post("/account/deposit").with(user(username)).param("accountType", "Savings").param("amount", + "75.50")).andExpect(status().is3xxRedirection()); + + assertEquals(0, new BigDecimal("75.50").compareTo(savingsBalance())); + + SavingsTransaction transaction = onlySavingsTransaction(); + assertEquals("Deposit to savings Account", transaction.getDescription()); + assertEquals(75.50, transaction.getAmount(), 0.001); + assertEquals(0, new BigDecimal("75.50").compareTo(transaction.getAvailableBalance())); + } + + @Test + public void withdrawDebitsPrimaryAccountAndWritesLedgerRow() throws Exception { + deposit("Primary", "400.00"); + + mockMvc.perform(post("/account/withdraw").with(user(username)).param("accountType", "Primary").param("amount", + "150.00")).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/userFront")); + + assertEquals(0, new BigDecimal("250.00").compareTo(primaryBalance())); + + PrimaryTransaction withdrawal = lastPrimaryTransaction(); + assertEquals("Withdraw from Primary Account", withdrawal.getDescription()); + // The withdrawal is recorded as a positive amount; only availableBalance moves down. + assertEquals(150.00, withdrawal.getAmount(), 0.001); + assertEquals(0, new BigDecimal("250.00").compareTo(withdrawal.getAvailableBalance())); + } + + @Test + public void withdrawDebitsSavingsAccountAndWritesLedgerRow() throws Exception { + deposit("Savings", "300.00"); + + mockMvc.perform(post("/account/withdraw").with(user(username)).param("accountType", "Savings").param("amount", + "120.00")).andExpect(status().is3xxRedirection()); + + assertEquals(0, new BigDecimal("180.00").compareTo(savingsBalance())); + + SavingsTransaction withdrawal = lastSavingsTransaction(); + assertEquals("Withdraw from savings Account", withdrawal.getDescription()); + assertEquals(120.00, withdrawal.getAmount(), 0.001); + assertEquals(0, new BigDecimal("180.00").compareTo(withdrawal.getAvailableBalance())); + } + + @Test + public void betweenAccountsTransferPrimaryToSavingsMovesBalancesAndConservesTotal() throws Exception { + deposit("Primary", "500.00"); + BigDecimal totalBefore = primaryBalance().add(savingsBalance()); + + mockMvc.perform(post("/transfer/betweenAccounts").with(user(username)).param("transferFrom", "Primary") + .param("transferTo", "Savings").param("amount", "200.00")).andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrl("/userFront")); + + assertEquals(0, new BigDecimal("300.00").compareTo(primaryBalance())); + assertEquals(0, new BigDecimal("200.00").compareTo(savingsBalance())); + assertEquals(0, totalBefore.compareTo(primaryBalance().add(savingsBalance()))); + + PrimaryTransaction transfer = lastPrimaryTransaction(); + assertEquals("Between account transfer from Primary to Savings", transfer.getDescription()); + assertEquals("Account", transfer.getType()); + assertEquals(200.00, transfer.getAmount(), 0.001); + // Only the sending ledger is written in this direction. + assertTrue(savingsTransactions().isEmpty()); + } + + @Test + public void betweenAccountsTransferSavingsToPrimaryMovesBalancesAndConservesTotal() throws Exception { + deposit("Savings", "500.00"); + List primaryBefore = primaryTransactions(); + BigDecimal totalBefore = primaryBalance().add(savingsBalance()); + + mockMvc.perform(post("/transfer/betweenAccounts").with(user(username)).param("transferFrom", "Savings") + .param("transferTo", "Primary").param("amount", "125.00")).andExpect(status().is3xxRedirection()); + + assertEquals(0, new BigDecimal("125.00").compareTo(primaryBalance())); + assertEquals(0, new BigDecimal("375.00").compareTo(savingsBalance())); + assertEquals(0, totalBefore.compareTo(primaryBalance().add(savingsBalance()))); + + SavingsTransaction transfer = lastSavingsTransaction(); + assertEquals("Between account transfer from Savings to Primary", transfer.getDescription()); + assertEquals("Transfer", transfer.getType()); + assertEquals(125.00, transfer.getAmount(), 0.001); + // Only the sending ledger is written in this direction. + assertEquals(primaryBefore.size(), primaryTransactions().size()); + } + + @Test + public void recipientLifecycleSavesListsAndDeletes() throws Exception { + String recipientName = "Payee" + System.nanoTime(); + + mockMvc.perform(post("/transfer/recipient/save").with(user(username)).param("name", recipientName) + .param("email", "payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") + .param("description", "Rent")).andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrl("/transfer/recipient")); + + Recipient saved = recipientDao.findByName(recipientName); + assertNotNull(saved); + assertEquals("payee@example.com", saved.getEmail()); + assertEquals("987654321", saved.getAccountNumber()); + assertEquals(username, saved.getUser().getUsername()); + + mockMvc.perform(get("/transfer/recipient").with(user(username))).andExpect(status().isOk()) + .andExpect(view().name("recipient")).andExpect(model().attributeExists("recipientList")); + + // Delete is a GET today; COG-1155 converts it to a POST and updates this test. + mockMvc.perform(get("/transfer/recipient/delete").with(user(username)).param("recipientName", recipientName)) + .andExpect(status().isOk()).andExpect(view().name("recipient")); + + assertNull(recipientDao.findByName(recipientName)); + } + + @Test + public void transferToSomeoneElseDebitsTheSendingAccount() throws Exception { + deposit("Primary", "600.00"); + String recipientName = "Payee" + System.nanoTime(); + saveRecipient(recipientName); + + mockMvc.perform(post("/transfer/toSomeoneElse").with(user(username)).param("recipientName", recipientName) + .param("accountType", "Primary").param("amount", "175.00")).andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrl("/userFront")); + + assertEquals(0, new BigDecimal("425.00").compareTo(primaryBalance())); + + PrimaryTransaction debit = lastPrimaryTransaction(); + assertEquals("Transfer to recipient " + recipientName, debit.getDescription()); + assertEquals("Transfer", debit.getType()); + assertEquals("Finished", debit.getStatus()); + assertEquals(175.00, debit.getAmount(), 0.001); + assertEquals(0, new BigDecimal("425.00").compareTo(debit.getAvailableBalance())); + } + + private void deposit(String accountType, String amount) throws Exception { + mockMvc.perform(post("/account/deposit").with(user(username)).param("accountType", accountType).param("amount", + amount)).andExpect(status().is3xxRedirection()); + } + + private void saveRecipient(String recipientName) throws Exception { + mockMvc.perform(post("/transfer/recipient/save").with(user(username)).param("name", recipientName) + .param("email", "payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") + .param("description", "Rent")).andExpect(status().is3xxRedirection()); + } + + private BigDecimal primaryBalance() { + return reloadPrimaryAccount().getAccountBalance(); + } + + private BigDecimal savingsBalance() { + return reloadSavingsAccount().getAccountBalance(); + } + + private PrimaryAccount reloadPrimaryAccount() { + return primaryAccountDao.findByAccountNumber(userService.findByUsername(username).getPrimaryAccount() + .getAccountNumber()); + } + + private SavingsAccount reloadSavingsAccount() { + return savingsAccountDao.findByAccountNumber(userService.findByUsername(username).getSavingsAccount() + .getAccountNumber()); + } + + private List primaryTransactions() { + Long accountId = reloadPrimaryAccount().getId(); + List transactions = new ArrayList<>(); + for (PrimaryTransaction transaction : primaryTransactionDao.findAll()) { + if (accountId.equals(transaction.getPrimaryAccount().getId())) { + transactions.add(transaction); + } + } + Collections.sort(transactions, (a, b) -> a.getId().compareTo(b.getId())); + return transactions; + } + + private List savingsTransactions() { + Long accountId = reloadSavingsAccount().getId(); + List transactions = new ArrayList<>(); + for (SavingsTransaction transaction : savingsTransactionDao.findAll()) { + if (accountId.equals(transaction.getSavingsAccount().getId())) { + transactions.add(transaction); + } + } + Collections.sort(transactions, (a, b) -> a.getId().compareTo(b.getId())); + return transactions; + } + + private PrimaryTransaction onlyPrimaryTransaction() { + List transactions = primaryTransactions(); + assertEquals(1, transactions.size()); + return transactions.get(0); + } + + private SavingsTransaction onlySavingsTransaction() { + List transactions = savingsTransactions(); + assertEquals(1, transactions.size()); + return transactions.get(0); + } + + private PrimaryTransaction lastPrimaryTransaction() { + List transactions = primaryTransactions(); + return transactions.get(transactions.size() - 1); + } + + private SavingsTransaction lastSavingsTransaction() { + List transactions = savingsTransactions(); + return transactions.get(transactions.size() - 1); + } +} From 5faa676baf12510d571ab436989b4a125c6540c7 Mon Sep 17 00:00:00 2001 From: Devin AI Date: Thu, 24 Sep 2026 14:53:53 +0000 Subject: [PATCH 2/3] feature(COG-1143): assert recipient list contents and cover savings recipient transfer Co-Authored-By: patrick.bradley --- .../com/userFront/MoneyMovementSmokeTest.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java index 837607ee..87359588 100644 --- a/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java +++ b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import com.userFront.dao.PrimaryAccountDao; import com.userFront.dao.PrimaryTransactionDao; @@ -211,8 +212,9 @@ public void recipientLifecycleSavesListsAndDeletes() throws Exception { assertEquals("987654321", saved.getAccountNumber()); assertEquals(username, saved.getUser().getUsername()); - mockMvc.perform(get("/transfer/recipient").with(user(username))).andExpect(status().isOk()) - .andExpect(view().name("recipient")).andExpect(model().attributeExists("recipientList")); + MvcResult listed = mockMvc.perform(get("/transfer/recipient").with(user(username))).andExpect(status().isOk()) + .andExpect(view().name("recipient")).andExpect(model().attributeExists("recipientList")).andReturn(); + assertEquals(Collections.singletonList(recipientName), recipientNames(listed)); // Delete is a GET today; COG-1155 converts it to a POST and updates this test. mockMvc.perform(get("/transfer/recipient/delete").with(user(username)).param("recipientName", recipientName)) @@ -241,6 +243,36 @@ public void transferToSomeoneElseDebitsTheSendingAccount() throws Exception { assertEquals(0, new BigDecimal("425.00").compareTo(debit.getAvailableBalance())); } + @Test + public void transferToSomeoneElseDebitsTheSendingSavingsAccount() throws Exception { + deposit("Savings", "600.00"); + String recipientName = "Payee" + System.nanoTime(); + saveRecipient(recipientName); + + mockMvc.perform(post("/transfer/toSomeoneElse").with(user(username)).param("recipientName", recipientName) + .param("accountType", "Savings").param("amount", "175.00")).andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrl("/userFront")); + + assertEquals(0, new BigDecimal("425.00").compareTo(savingsBalance())); + + SavingsTransaction debit = lastSavingsTransaction(); + assertEquals("Transfer to recipient " + recipientName, debit.getDescription()); + assertEquals("Transfer", debit.getType()); + assertEquals("Finished", debit.getStatus()); + assertEquals(175.00, debit.getAmount(), 0.001); + assertEquals(0, new BigDecimal("425.00").compareTo(debit.getAvailableBalance())); + } + + @SuppressWarnings("unchecked") + private List recipientNames(MvcResult result) { + List recipients = (List) result.getModelAndView().getModel().get("recipientList"); + List names = new ArrayList<>(); + for (Recipient recipient : recipients) { + names.add(recipient.getName()); + } + return names; + } + private void deposit(String accountType, String amount) throws Exception { mockMvc.perform(post("/account/deposit").with(user(username)).param("accountType", accountType).param("amount", amount)).andExpect(status().is3xxRedirection()); From 3c929282ba658d25449ca643bb3099ca8500cde1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:27:14 +0000 Subject: [PATCH 3/3] feature(COG-1143): use canonical harness mockMvc, txsmoke- test data, isolate recipient delete request Co-Authored-By: patrick.bradley --- .../com/userFront/MoneyMovementSmokeTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java index 87359588..13dcf74f 100644 --- a/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java +++ b/UserFront/src/test/java/com/userFront/MoneyMovementSmokeTest.java @@ -23,8 +23,8 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultActions; import com.userFront.dao.PrimaryAccountDao; import com.userFront.dao.PrimaryTransactionDao; @@ -50,9 +50,6 @@ public class MoneyMovementSmokeTest extends AbstractIntegrationTest { private static final AtomicInteger SEQ = new AtomicInteger(); - @Autowired - private MockMvc mockMvc; - @Autowired private UserService userService; @@ -76,13 +73,13 @@ public class MoneyMovementSmokeTest extends AbstractIntegrationTest { @Before public void createUser() { int n = SEQ.incrementAndGet(); - username = "smoke" + System.nanoTime() + n; + username = "txsmoke-" + System.nanoTime() + "-" + n; User user = new User(); user.setUsername(username); user.setPassword("password"); user.setFirstName("Smoke"); - user.setLastName("Test"); + user.setLastName("TxSmoke"); user.setEmail(username + "@example.com"); user.setPhone("5551234567"); @@ -199,16 +196,16 @@ public void betweenAccountsTransferSavingsToPrimaryMovesBalancesAndConservesTota @Test public void recipientLifecycleSavesListsAndDeletes() throws Exception { - String recipientName = "Payee" + System.nanoTime(); + String recipientName = "txsmoke-payee-" + System.nanoTime(); mockMvc.perform(post("/transfer/recipient/save").with(user(username)).param("name", recipientName) - .param("email", "payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") + .param("email", "txsmoke-payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") .param("description", "Rent")).andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("/transfer/recipient")); Recipient saved = recipientDao.findByName(recipientName); assertNotNull(saved); - assertEquals("payee@example.com", saved.getEmail()); + assertEquals("txsmoke-payee@example.com", saved.getEmail()); assertEquals("987654321", saved.getAccountNumber()); assertEquals(username, saved.getUser().getUsername()); @@ -216,9 +213,7 @@ public void recipientLifecycleSavesListsAndDeletes() throws Exception { .andExpect(view().name("recipient")).andExpect(model().attributeExists("recipientList")).andReturn(); assertEquals(Collections.singletonList(recipientName), recipientNames(listed)); - // Delete is a GET today; COG-1155 converts it to a POST and updates this test. - mockMvc.perform(get("/transfer/recipient/delete").with(user(username)).param("recipientName", recipientName)) - .andExpect(status().isOk()).andExpect(view().name("recipient")); + deleteRecipient(recipientName).andExpect(status().isOk()).andExpect(view().name("recipient")); assertNull(recipientDao.findByName(recipientName)); } @@ -226,7 +221,7 @@ public void recipientLifecycleSavesListsAndDeletes() throws Exception { @Test public void transferToSomeoneElseDebitsTheSendingAccount() throws Exception { deposit("Primary", "600.00"); - String recipientName = "Payee" + System.nanoTime(); + String recipientName = "txsmoke-payee-" + System.nanoTime(); saveRecipient(recipientName); mockMvc.perform(post("/transfer/toSomeoneElse").with(user(username)).param("recipientName", recipientName) @@ -246,7 +241,7 @@ public void transferToSomeoneElseDebitsTheSendingAccount() throws Exception { @Test public void transferToSomeoneElseDebitsTheSendingSavingsAccount() throws Exception { deposit("Savings", "600.00"); - String recipientName = "Payee" + System.nanoTime(); + String recipientName = "txsmoke-payee-" + System.nanoTime(); saveRecipient(recipientName); mockMvc.perform(post("/transfer/toSomeoneElse").with(user(username)).param("recipientName", recipientName) @@ -273,6 +268,11 @@ private List recipientNames(MvcResult result) { return names; } + /** Delete is a GET today; COG-1155 converts it to a POST. */ + private ResultActions deleteRecipient(String recipientName) throws Exception { + return mockMvc.perform(get("/transfer/recipient/delete").with(user(username)).param("recipientName", recipientName)); + } + private void deposit(String accountType, String amount) throws Exception { mockMvc.perform(post("/account/deposit").with(user(username)).param("accountType", accountType).param("amount", amount)).andExpect(status().is3xxRedirection()); @@ -280,7 +280,7 @@ private void deposit(String accountType, String amount) throws Exception { private void saveRecipient(String recipientName) throws Exception { mockMvc.perform(post("/transfer/recipient/save").with(user(username)).param("name", recipientName) - .param("email", "payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") + .param("email", "txsmoke-payee@example.com").param("phone", "5559876543").param("accountNumber", "987654321") .param("description", "Rent")).andExpect(status().is3xxRedirection()); }