diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d45fd94..1da4248 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -50,10 +50,6 @@ public class Main { printAccountBalance(card, ledger); printAccountBalance(cash, ledger); -// operation5.removeLine(0); -// operationService.post(operation5); -// System.out.println("Удаление строк"); - Operation operation6 = Operation.income(LocalDate.now(), 504L, card); operationLine = new OperationLine(new Category(4L, "Salary"), new BigDecimal(20000)); operation6.addLine(operationLine); diff --git a/src/main/java/net/sytes/kashey/easymoney/config/AccountingConfig.java b/src/main/java/net/sytes/kashey/easymoney/config/AccountingConfig.java index cda300d..d7f1cf7 100644 --- a/src/main/java/net/sytes/kashey/easymoney/config/AccountingConfig.java +++ b/src/main/java/net/sytes/kashey/easymoney/config/AccountingConfig.java @@ -20,18 +20,10 @@ public class AccountingConfig { } @Bean - public OperationService operationService( - OperationJournal journal, - Ledger ledger - ) { + public OperationService operationService(OperationJournal journal, Ledger ledger) { return new OperationService(journal, ledger); } - @Bean - public AccountStore accountStore() { - return new InMemoryAccountStore(); - } - @Bean public AccountService accountService(AccountStore accountStore) { return new AccountService(accountStore); diff --git a/src/main/java/net/sytes/kashey/easymoney/config/PersistenceConfig.java b/src/main/java/net/sytes/kashey/easymoney/config/PersistenceConfig.java new file mode 100644 index 0000000..6ec2df7 --- /dev/null +++ b/src/main/java/net/sytes/kashey/easymoney/config/PersistenceConfig.java @@ -0,0 +1,16 @@ +package net.sytes.kashey.easymoney.config; + +import net.sytes.kashey.easymoney.persistence.AccountRepository; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.simple.JdbcClient; +import service.AccountStore; + +@Configuration +public class PersistenceConfig { + + @Bean + public AccountStore accountStore(JdbcClient jdbcClient) { + return new AccountRepository(jdbcClient); + } +} \ No newline at end of file diff --git a/src/test/java/net/sytes/kashey/easymoney/api/AccountControllerTest.java b/src/test/java/net/sytes/kashey/easymoney/api/AccountControllerTest.java index b9be7ec..04ac4c6 100644 --- a/src/test/java/net/sytes/kashey/easymoney/api/AccountControllerTest.java +++ b/src/test/java/net/sytes/kashey/easymoney/api/AccountControllerTest.java @@ -3,6 +3,7 @@ package net.sytes.kashey.easymoney.api; import model.Account; import model.Operation; import net.sytes.kashey.easymoney.config.AccountingConfig; +import net.sytes.kashey.easymoney.config.InMemoryStorageTestConfig; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; @@ -29,7 +30,10 @@ import java.math.BigDecimal; import java.time.LocalDate; @WebMvcTest(AccountController.class) -@Import(AccountingConfig.class) +@Import({ + AccountingConfig.class, + InMemoryStorageTestConfig.class +}) class AccountControllerTest { @Autowired diff --git a/src/test/java/net/sytes/kashey/easymoney/api/OperationControllerTest.java b/src/test/java/net/sytes/kashey/easymoney/api/OperationControllerTest.java index 8ca75a1..d698bac 100644 --- a/src/test/java/net/sytes/kashey/easymoney/api/OperationControllerTest.java +++ b/src/test/java/net/sytes/kashey/easymoney/api/OperationControllerTest.java @@ -3,6 +3,7 @@ package net.sytes.kashey.easymoney.api; import model.Account; import model.Operation; import model.OperationType; +import net.sytes.kashey.easymoney.config.InMemoryStorageTestConfig; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest; @@ -27,7 +28,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @WebMvcTest(OperationController.class) -@Import(AccountingConfig.class) +@Import({ + AccountingConfig.class, + InMemoryStorageTestConfig.class +}) class OperationControllerTest { @Autowired diff --git a/src/test/java/net/sytes/kashey/easymoney/config/InMemoryStorageTestConfig.java b/src/test/java/net/sytes/kashey/easymoney/config/InMemoryStorageTestConfig.java new file mode 100644 index 0000000..42a609d --- /dev/null +++ b/src/test/java/net/sytes/kashey/easymoney/config/InMemoryStorageTestConfig.java @@ -0,0 +1,15 @@ +package net.sytes.kashey.easymoney.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import service.AccountStore; +import service.InMemoryAccountStore; + +@TestConfiguration +public class InMemoryStorageTestConfig { + + @Bean + public AccountStore accountStore() { + return new InMemoryAccountStore(); + } +} \ No newline at end of file