diff --git a/.gitignore b/.gitignore
index 4202f39..92cfe30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -114,4 +114,4 @@ Temporary Items
.mvn/*
mvnw*
#maven build target
-target/
\ No newline at end of file
+target/
diff --git a/pom.xml b/pom.xml
index 0a99788..5b58ae5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,14 +14,14 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.4.RELEASE
+ 2.0.0.RELEASE
UTF-8
UTF-8
- 1.7
+ 9
@@ -39,16 +39,32 @@
test
- org.hsqldb
- hsqldb
- runtime
+ com.h2database
+ h2
-
javax.inject
javax.inject
1
+
+
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.2.11
+
+
+ com.sun.xml.bind
+ jaxb-core
+ 2.2.11
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ 2.2.11
+
diff --git a/src/main/java/io/zipcoder/ZcwbankApplication.java b/src/main/java/io/zipcoder/ZcwbankApplication.java
index 60df46b..8c7b107 100644
--- a/src/main/java/io/zipcoder/ZcwbankApplication.java
+++ b/src/main/java/io/zipcoder/ZcwbankApplication.java
@@ -6,7 +6,7 @@
@SpringBootApplication
public class ZcwbankApplication {
- public static void main(String[] args) {
- SpringApplication.run(ZcwbankApplication.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(ZcwbankApplication.class, args);
+ }
}
diff --git a/src/main/java/io/zipcoder/controller/AccountController.java b/src/main/java/io/zipcoder/controller/AccountController.java
new file mode 100644
index 0000000..90b0abb
--- /dev/null
+++ b/src/main/java/io/zipcoder/controller/AccountController.java
@@ -0,0 +1,58 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.service.interfaces.AccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@RestController
+public class AccountController {
+ private AccountService accountService;
+
+ @Autowired
+ public AccountController(AccountService accountService) {
+ this.accountService = accountService;
+ }
+
+ @RequestMapping(value = "/accounts", method = GET)
+ public ResponseEntity> getAllAccounts() {
+ return accountService.getAllAccounts();
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}", method = GET)
+ public ResponseEntity getAccountById(@PathVariable("accountId") Long accountId) {
+ return accountService.getAccountById(accountId);
+ }
+
+ @RequestMapping(value = "/customers/{customerId}/accounts", method = GET)
+ public ResponseEntity> getAccountsByCustomerId(@PathVariable("customerId") Long customerId) {
+ return accountService.getAccountsByCustomerId(customerId);
+ }
+
+ @RequestMapping(value = "/customers/{customerId}/accounts", method = POST)
+ public ResponseEntity createAccount(@RequestBody Account account, @PathVariable("customerId") Long customerId) {
+ return accountService.createAccount(account, customerId);
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}", method = PUT)
+ public ResponseEntity updateAccount(@RequestBody Account account, @PathVariable("accountId") Long accountId) {
+ return accountService.updateAccount(account, accountId);
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}", method = DELETE)
+ public ResponseEntity deleteAccountById(@PathVariable("accountId") Long accountId) {
+ return accountService.deleteAccountById(accountId);
+ }
+}
diff --git a/src/main/java/io/zipcoder/controller/BillController.java b/src/main/java/io/zipcoder/controller/BillController.java
new file mode 100644
index 0000000..a64e44e
--- /dev/null
+++ b/src/main/java/io/zipcoder/controller/BillController.java
@@ -0,0 +1,57 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Bill;
+import io.zipcoder.service.interfaces.BillService;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@RestController
+public class BillController {
+
+ private BillService billService;
+
+ public BillController(BillService billService) {
+ this.billService = billService;
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/bills", method = GET)
+ public ResponseEntity> getBillsByAccountId(@PathVariable("accountId") Long accountId) {
+ return billService.getBillsByAccountId(accountId);
+ }
+
+ @RequestMapping(value = "/bills/{billId}", method = GET)
+ public ResponseEntity getBillById(@PathVariable("billId") Long billId) {
+ return billService.getBillById(billId);
+ }
+
+ @RequestMapping(value = "/customers/{customerId}/bills", method = GET)
+ public ResponseEntity> getBillsByCustomerId(@PathVariable("customerId") Long customerId) {
+ return billService.getBillsByCustomerId(customerId);
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/bills", method = POST)
+ public ResponseEntity createBill(@RequestBody Bill bill, @PathVariable("accountId") Long accountId) {
+ return billService.createBill(bill, accountId);
+ }
+
+ @RequestMapping(value = "/bills/{billId}", method = PUT)
+ public ResponseEntity updateBill(@RequestBody Bill bill, @PathVariable("billId") Long billId) {
+ return billService.updateBill(bill, billId);
+ }
+
+ @RequestMapping(value = "/bills/{billId}", method = DELETE)
+ public ResponseEntity deleteBillById(@PathVariable("billId") Long billId) {
+ return billService.deleteBillById(billId);
+ }
+}
diff --git a/src/main/java/io/zipcoder/controller/CustomerController.java b/src/main/java/io/zipcoder/controller/CustomerController.java
new file mode 100644
index 0000000..a7d893e
--- /dev/null
+++ b/src/main/java/io/zipcoder/controller/CustomerController.java
@@ -0,0 +1,60 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Customer;
+import io.zipcoder.service.interfaces.CustomerService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@RestController
+public class CustomerController {
+
+ private CustomerService customerService;
+
+ @Autowired
+ public CustomerController(CustomerService customerService) {
+ this.customerService = customerService;
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/customer", method = GET)
+ public ResponseEntity getCustomerByAccountId(@PathVariable("accountId") Long accountId) {
+ return customerService.getCustomerByAccountId(accountId);
+ }
+
+ @RequestMapping(value = "/customers", method = GET)
+ public ResponseEntity> getAllCustomers() {
+ return customerService.getAllCustomers();
+ }
+
+ @RequestMapping(value = "/customers/{customerId}", method = GET)
+ public ResponseEntity getCustomerById(@PathVariable("customerId") Long customerId) {
+ return customerService.getCustomerById(customerId);
+ }
+
+ @RequestMapping(value = "/customers", method = POST)
+ public ResponseEntity createCustomer(@RequestBody Customer customer) {
+ return customerService.createCustomer(customer);
+ }
+
+ @RequestMapping(value = "/customers/{customerId}", method = PUT)
+ public ResponseEntity updateCustomer(@RequestBody Customer customer, @PathVariable("customerId") Long customerId) {
+ return customerService.updateCustomer(customer, customerId);
+ }
+
+ @RequestMapping(value = "/customers/{customerId}", method = DELETE)
+ public ResponseEntity deleteCustomer(@PathVariable("customerId") Long customerId) {
+ return customerService.deleteCustomerById(customerId);
+ }
+}
diff --git a/src/main/java/io/zipcoder/controller/DepositController.java b/src/main/java/io/zipcoder/controller/DepositController.java
new file mode 100644
index 0000000..c1b7f91
--- /dev/null
+++ b/src/main/java/io/zipcoder/controller/DepositController.java
@@ -0,0 +1,52 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Deposit;
+import io.zipcoder.service.interfaces.DepositService;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@RestController
+public class DepositController {
+
+ private DepositService depositService;
+
+ public DepositController(DepositService depositService) {
+ this.depositService = depositService;
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/deposits", method = GET)
+ public ResponseEntity> getAllDepositsByAccountId(@PathVariable("accountId") Long accountId) {
+ return depositService.getAllDepositsByAccountId(accountId);
+ }
+
+ @RequestMapping(value = "/deposits/{depositId}", method = GET)
+ public ResponseEntity getDepositById(@PathVariable("depositId") Long depositId) {
+ return depositService.getDepositById(depositId);
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/deposits", method = POST)
+ public ResponseEntity createDeposit(@RequestBody Deposit deposit, @PathVariable("accountId") Long accountId) {
+ return depositService.createDeposit(deposit, accountId);
+ }
+
+ @RequestMapping(value = "/deposits/{depositId}", method = PUT)
+ public ResponseEntity updateDeposit(@RequestBody Deposit deposit, @PathVariable("depositId") Long depositId) {
+ return depositService.updateDeposit(deposit, depositId);
+ }
+
+ @RequestMapping(value = "/deposits/{depositId}", method = DELETE)
+ public ResponseEntity deleteDepositById(@PathVariable("depositId") Long depositId) {
+ return depositService.deleteDepositById(depositId);
+ }
+}
diff --git a/src/main/java/io/zipcoder/controller/WithdrawalController.java b/src/main/java/io/zipcoder/controller/WithdrawalController.java
new file mode 100644
index 0000000..fcb9cc1
--- /dev/null
+++ b/src/main/java/io/zipcoder/controller/WithdrawalController.java
@@ -0,0 +1,53 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Withdrawal;
+import io.zipcoder.service.interfaces.WithdrawalService;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@RestController
+public class WithdrawalController {
+
+ private WithdrawalService withdrawalService;
+
+ public WithdrawalController(WithdrawalService withdrawalService) {
+ this.withdrawalService = withdrawalService;
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/withdrawals", method = GET)
+ public ResponseEntity> getAllWithdrawalsByAccountId(@PathVariable("accountId") Long accountId) {
+ return withdrawalService.getAllWithdrawalsByAccountId(accountId);
+ }
+
+ @RequestMapping(value = "/withdrawals/{withdrawalId}", method = GET)
+ public ResponseEntity getWithdrawalById(@PathVariable("withdrawalId") Long withdrawalId) {
+ return withdrawalService.getWithdrawalById(withdrawalId);
+ }
+
+ @RequestMapping(value = "/accounts/{accountId}/withdrawal", method = POST)
+ public ResponseEntity createWithdrawal(@RequestBody Withdrawal withdrawal, @PathVariable("accountId") Long accountId) {
+ return withdrawalService.createWithdrawal(withdrawal, accountId);
+ }
+
+ @RequestMapping(value = "/withdrawals/{withdrawalId}", method = PUT)
+ public ResponseEntity updateWithdrawal(@RequestBody Withdrawal withdrawal, @PathVariable("withdrawalId") Long withdrawalId) {
+ return withdrawalService.updateWithdrawal(withdrawal, withdrawalId);
+ }
+
+ @RequestMapping(value = "/withdrawals/{withdrawalId}", method = DELETE)
+ public ResponseEntity deleteWithdrawalById(@PathVariable("withdrawalId") Long withdrawalId) {
+ return withdrawalService.deleteWithdrawalById(withdrawalId);
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Account.java b/src/main/java/io/zipcoder/domain/Account.java
new file mode 100644
index 0000000..82f062c
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Account.java
@@ -0,0 +1,77 @@
+package io.zipcoder.domain;
+
+import javax.persistence.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Entity
+public class Account {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String type;
+ private String nickname;
+ private Integer rewards;
+ private Double balance;
+
+ @ManyToOne
+ @JoinColumn(name = "customer_id")
+ private Customer customer;
+
+ public Account() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public Integer getRewards() {
+ return rewards;
+ }
+
+ public void setRewards(Integer rewards) {
+ this.rewards = rewards;
+ }
+
+ public Double getBalance() {
+ return balance;
+ }
+
+ public void setBalance(Double balance) {
+ this.balance = balance;
+ }
+
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Address.java b/src/main/java/io/zipcoder/domain/Address.java
new file mode 100644
index 0000000..e8a4d20
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Address.java
@@ -0,0 +1,83 @@
+package io.zipcoder.domain;
+
+import javax.persistence.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@Entity
+public class Address {
+ @Id
+ @GeneratedValue
+ private Long id;
+ private String street_number;
+ private String street_name;
+ private String city;
+ private String state;
+ private String zip;
+ @OneToOne
+ @JoinColumn(name = "customer_id")
+ private Customer customer;
+
+ public Address() {
+ }
+
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getStreet_number() {
+ return street_number;
+ }
+
+ public void setStreet_number(String street_number) {
+ this.street_number = street_number;
+ }
+
+ public String getStreet_name() {
+ return street_name;
+ }
+
+ public void setStreet_name(String street_name) {
+ this.street_name = street_name;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Bill.java b/src/main/java/io/zipcoder/domain/Bill.java
new file mode 100644
index 0000000..75d5a35
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Bill.java
@@ -0,0 +1,103 @@
+package io.zipcoder.domain;
+
+import javax.persistence.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@Entity
+public class Bill {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String status;
+ private String payee;
+ private String creation_date;
+ private String payment_date;
+ private Integer recurring_date;
+ private String upcoming_payment_date;
+ private Double payment_amount;
+
+ @ManyToOne
+ @JoinColumn(name = "account_id")
+ private Account account;
+
+ public Bill() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getPayee() {
+ return payee;
+ }
+
+ public void setPayee(String payee) {
+ this.payee = payee;
+ }
+
+ public String getCreation_date() {
+ return creation_date;
+ }
+
+ public void setCreation_date(String creation_date) {
+ this.creation_date = creation_date;
+ }
+
+ public String getPayment_date() {
+ return payment_date;
+ }
+
+ public void setPayment_date(String payment_date) {
+ this.payment_date = payment_date;
+ }
+
+ public Integer getRecurring_date() {
+ return recurring_date;
+ }
+
+ public void setRecurring_date(Integer recurring_date) {
+ this.recurring_date = recurring_date;
+ }
+
+ public String getUpcoming_payment_date() {
+ return upcoming_payment_date;
+ }
+
+ public void setUpcoming_payment_date(String upcoming_payment_date) {
+ this.upcoming_payment_date = upcoming_payment_date;
+ }
+
+ public Double getPayment_amount() {
+ return payment_amount;
+ }
+
+ public void setPayment_amount(Double payment_amount) {
+ this.payment_amount = payment_amount;
+ }
+
+ public Account getAccount() {
+ return account;
+ }
+
+ public void setAccount(Account account) {
+ this.account = account;
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Customer.java b/src/main/java/io/zipcoder/domain/Customer.java
new file mode 100644
index 0000000..bb2fef5
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Customer.java
@@ -0,0 +1,69 @@
+package io.zipcoder.domain;
+
+import javax.persistence.*;
+import java.util.List;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Entity
+public class Customer {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String first_name;
+ private String last_name;
+
+ @OneToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "address_id")
+ private Address address;
+
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "customer_id")
+ private List accounts;
+
+ public List getAccounts() {
+ return accounts;
+ }
+
+ public void setAccounts(List accounts) {
+ this.accounts = accounts;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getFirst_name() {
+ return first_name;
+ }
+
+ public void setFirst_name(String first_name) {
+ this.first_name = first_name;
+ }
+
+ public String getLast_name() {
+ return last_name;
+ }
+
+ public void setLast_name(String last_name) {
+ this.last_name = last_name;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Deposit.java b/src/main/java/io/zipcoder/domain/Deposit.java
new file mode 100644
index 0000000..152b184
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Deposit.java
@@ -0,0 +1,89 @@
+package io.zipcoder.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Entity
+public class Deposit {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String type;
+ private String transaction_date;
+
+ @ManyToOne
+ private Account account;
+
+ private String medium;
+ private Double amount;
+ private String description;
+
+ public Deposit() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getTransaction_date() {
+ return transaction_date;
+ }
+
+ public void setTransaction_date(String transaction_date) {
+ this.transaction_date = transaction_date;
+ }
+
+ public Account getAccount() {
+ return account;
+ }
+
+ public void setAccount(Account account) {
+ this.account = account;
+ }
+
+ public String getMedium() {
+ return medium;
+ }
+
+ public void setMedium(String medium) {
+ this.medium = medium;
+ }
+
+ public Double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(Double amount) {
+ this.amount = amount;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
diff --git a/src/main/java/io/zipcoder/domain/Withdrawal.java b/src/main/java/io/zipcoder/domain/Withdrawal.java
new file mode 100644
index 0000000..846074e
--- /dev/null
+++ b/src/main/java/io/zipcoder/domain/Withdrawal.java
@@ -0,0 +1,98 @@
+package io.zipcoder.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.domain
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Entity
+public class Withdrawal {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ private String type;
+ private String transaction_date;
+ private String status;
+
+ @ManyToOne
+ private Account account;
+
+ private String medium;
+ private Double amount;
+ private String description;
+
+ public Withdrawal() {
+ }
+
+ public Account getAccount() {
+ return account;
+ }
+
+ public void setAccount(Account account) {
+ this.account = account;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getTransaction_date() {
+ return transaction_date;
+ }
+
+ public void setTransaction_date(String transaction_date) {
+ this.transaction_date = transaction_date;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getMedium() {
+ return medium;
+ }
+
+ public void setMedium(String medium) {
+ this.medium = medium;
+ }
+
+ public Double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(Double amount) {
+ this.amount = amount;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
diff --git a/src/main/java/io/zipcoder/repository/AccountRepository.java b/src/main/java/io/zipcoder/repository/AccountRepository.java
new file mode 100644
index 0000000..9b54334
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/AccountRepository.java
@@ -0,0 +1,14 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Account;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface AccountRepository extends CrudRepository {
+ Iterable findAllByCustomer_Id(Long customerId);
+}
diff --git a/src/main/java/io/zipcoder/repository/AddressRepository.java b/src/main/java/io/zipcoder/repository/AddressRepository.java
new file mode 100644
index 0000000..7e7fcce
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/AddressRepository.java
@@ -0,0 +1,14 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Address;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface AddressRepository extends CrudRepository {
+ Address findByCustomer_Id(Long customerId);
+}
diff --git a/src/main/java/io/zipcoder/repository/BillRepository.java b/src/main/java/io/zipcoder/repository/BillRepository.java
new file mode 100644
index 0000000..a67a516
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/BillRepository.java
@@ -0,0 +1,17 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Bill;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+public interface BillRepository extends CrudRepository {
+ Iterable findAllByAccount_Id(Long accountId);
+
+ Iterable findAllByAccount_Customer_Id(Long customerId);
+}
diff --git a/src/main/java/io/zipcoder/repository/CustomerRepository.java b/src/main/java/io/zipcoder/repository/CustomerRepository.java
new file mode 100644
index 0000000..0a307ff
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/CustomerRepository.java
@@ -0,0 +1,13 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Customer;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface CustomerRepository extends CrudRepository {
+}
diff --git a/src/main/java/io/zipcoder/repository/DepositRepository.java b/src/main/java/io/zipcoder/repository/DepositRepository.java
new file mode 100644
index 0000000..9fa152b
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/DepositRepository.java
@@ -0,0 +1,16 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Deposit;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface DepositRepository extends CrudRepository {
+ Iterable getDepositsByAccount_Id(Long accountId);
+
+ Deposit getDepositById(Long id);
+}
diff --git a/src/main/java/io/zipcoder/repository/WithdrawalRepository.java b/src/main/java/io/zipcoder/repository/WithdrawalRepository.java
new file mode 100644
index 0000000..87a62a7
--- /dev/null
+++ b/src/main/java/io/zipcoder/repository/WithdrawalRepository.java
@@ -0,0 +1,17 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Withdrawal;
+import org.springframework.data.repository.CrudRepository;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface WithdrawalRepository extends CrudRepository {
+ Iterable findAllByAccount_Id(Long accountId);
+
+ Withdrawal getById(Long withdrawalId);
+}
+
diff --git a/src/main/java/io/zipcoder/service/implementations/AccountServiceImpl.java b/src/main/java/io/zipcoder/service/implementations/AccountServiceImpl.java
new file mode 100644
index 0000000..bbe29eb
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/implementations/AccountServiceImpl.java
@@ -0,0 +1,73 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.CustomerRepository;
+import io.zipcoder.service.interfaces.AccountService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import static org.springframework.http.HttpStatus.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Service
+public class AccountServiceImpl implements AccountService {
+
+ private AccountRepository accountRepo;
+ private CustomerRepository customerRepo;
+
+ @Autowired
+ public AccountServiceImpl(AccountRepository accountRepo, CustomerRepository customerRepo) {
+ this.accountRepo = accountRepo;
+ this.customerRepo = customerRepo;
+ }
+
+ public ResponseEntity getAccountById(Long accountId) {
+ Account account = accountRepo.findById(accountId).orElse(new Account());
+ return new ResponseEntity<>(account, OK);
+ }
+
+ public ResponseEntity> getAccountsByCustomerId(Long customerId) {
+ Iterable accounts = accountRepo.findAllByCustomer_Id(customerId);
+ return new ResponseEntity<>(accounts, OK);
+ }
+
+ public ResponseEntity createAccount(Account account, Long customerId) {
+ try {
+ Customer customer = customerRepo.findById(customerId).orElseThrow(Exception::new);
+ account.setCustomer(customer);
+ Account returnedAccount = accountRepo.save(account);
+ return new ResponseEntity<>(returnedAccount, CREATED);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Account(), BAD_REQUEST);
+ }
+ }
+
+ public ResponseEntity updateAccount(Account account, Long accountId) {
+ try {
+ account.setId(accountId);
+ Account returnedAccount = accountRepo.save(account);
+ return new ResponseEntity<>(returnedAccount, OK);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Account(), BAD_REQUEST);
+ }
+ }
+
+ public ResponseEntity deleteAccountById(Long accountId) {
+ accountRepo.deleteById(accountId);
+ return new ResponseEntity(OK);
+ }
+
+ public ResponseEntity> getAllAccounts() {
+ Iterable accounts = accountRepo.findAll();
+ return new ResponseEntity<>(accounts, OK);
+ }
+}
diff --git a/src/main/java/io/zipcoder/service/implementations/BillServiceImpl.java b/src/main/java/io/zipcoder/service/implementations/BillServiceImpl.java
new file mode 100644
index 0000000..350312a
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/implementations/BillServiceImpl.java
@@ -0,0 +1,74 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Bill;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.BillRepository;
+import io.zipcoder.service.interfaces.BillService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import java.util.Optional;
+
+import static org.springframework.http.HttpStatus.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Service
+public class BillServiceImpl implements BillService {
+
+ private BillRepository billRepo;
+ private AccountRepository accountRepo;
+
+ @Autowired
+ public BillServiceImpl(BillRepository billRepo, AccountRepository accountRepo) {
+ this.billRepo = billRepo;
+ this.accountRepo = accountRepo;
+ }
+
+ public ResponseEntity> getBillsByAccountId(Long accountId) {
+ Iterable bills = billRepo.findAllByAccount_Id(accountId);
+ return new ResponseEntity<>(bills, OK);
+ }
+
+ public ResponseEntity getBillById(Long id) {
+ Optional billOrNah = billRepo.findById(id);
+ Bill bill = billOrNah.orElse(new Bill());
+ HttpStatus status = billOrNah.isPresent() ? OK : NOT_FOUND;
+ return new ResponseEntity<>(bill, status);
+ }
+
+ public ResponseEntity> getBillsByCustomerId(Long customerId) {
+ Iterable bills = billRepo.findAllByAccount_Customer_Id(customerId);
+ return new ResponseEntity<>(bills, OK);
+ }
+
+ public ResponseEntity createBill(Bill bill, Long accountId) {
+ try {
+ Account account = accountRepo.findById(accountId).orElseThrow(Exception::new);
+ bill.setAccount(account);
+ Bill returnedBill = billRepo.save(bill);
+ return new ResponseEntity<>(returnedBill, CREATED);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Bill(), BAD_REQUEST);
+ }
+ }
+
+ public ResponseEntity updateBill(Bill bill, Long billId) {
+ bill.setId(billId);
+ Bill returnedBill = billRepo.save(bill);
+ return new ResponseEntity<>(returnedBill, OK);
+ }
+
+ public ResponseEntity deleteBillById(Long billId) {
+ billRepo.deleteById(billId);
+ return new ResponseEntity(OK);
+ }
+}
diff --git a/src/main/java/io/zipcoder/service/implementations/CustomerServiceImpl.java b/src/main/java/io/zipcoder/service/implementations/CustomerServiceImpl.java
new file mode 100644
index 0000000..a88c163
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/implementations/CustomerServiceImpl.java
@@ -0,0 +1,75 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.CustomerRepository;
+import io.zipcoder.service.interfaces.CustomerService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import static org.springframework.http.HttpStatus.*;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@Service
+public class CustomerServiceImpl implements CustomerService {
+
+ private CustomerRepository customerRepo;
+ private AccountRepository accountRepo;
+
+ @Autowired
+ public CustomerServiceImpl(CustomerRepository customerRepo, AccountRepository accountRepo) {
+ this.customerRepo = customerRepo;
+ this.accountRepo = accountRepo;
+ }
+
+ public ResponseEntity getCustomerByAccountId(Long accountId) {
+ try {
+ Account returnedAccount = accountRepo.findById(accountId).orElseThrow(Exception::new);
+ Customer foundCustomer = returnedAccount.getCustomer();
+ return new ResponseEntity<>(foundCustomer, OK);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Customer(), BAD_REQUEST);
+ }
+ }
+
+ public ResponseEntity> getAllCustomers() {
+ Iterable foundCustomers = customerRepo.findAll();
+ return new ResponseEntity<>(foundCustomers, OK);
+ }
+
+ public ResponseEntity getCustomerById(Long customerId) {
+ Customer foundCustomer = customerRepo.findById(customerId).orElse(new Customer());
+ return new ResponseEntity<>(foundCustomer, OK);
+ }
+
+ public ResponseEntity createCustomer(Customer customer) {
+ Customer returnedCustomer = customerRepo.save(customer);
+ return new ResponseEntity<>(returnedCustomer, CREATED);
+ }
+
+ public ResponseEntity updateCustomer(Customer customer, Long customerId) {
+ try {
+ if (!customerRepo.existsById(customerId))
+ throw new Exception();
+
+ customer.setId(customerId);
+ Customer returnedCustomer = customerRepo.save(customer);
+ return new ResponseEntity<>(returnedCustomer, OK);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Customer(), BAD_REQUEST);
+ }
+ }
+
+ public ResponseEntity deleteCustomerById(Long customerId) {
+ customerRepo.deleteById(customerId);
+ return new ResponseEntity(OK);
+ }
+}
diff --git a/src/main/java/io/zipcoder/service/implementations/DepositServiceImpl.java b/src/main/java/io/zipcoder/service/implementations/DepositServiceImpl.java
new file mode 100644
index 0000000..c7327c8
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/implementations/DepositServiceImpl.java
@@ -0,0 +1,66 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Deposit;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.DepositRepository;
+import io.zipcoder.service.interfaces.DepositService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@Service
+public class DepositServiceImpl implements DepositService {
+
+ private AccountRepository accountRepo;
+ private DepositRepository depositRepo;
+
+ @Autowired
+ public DepositServiceImpl(DepositRepository depositRepo, AccountRepository accountRepo) {
+ this.depositRepo = depositRepo;
+ this.accountRepo = accountRepo;
+ }
+
+ public ResponseEntity> getAllDepositsByAccountId(Long accountId) {
+ //TODO: Check if account exists
+ Iterable allDeposits = depositRepo.getDepositsByAccount_Id(accountId);
+ return new ResponseEntity<>(allDeposits, HttpStatus.OK);
+ }
+
+ public ResponseEntity getDepositById(Long depositId) {
+ //TODO: Check if deposit id exists
+ Deposit deposit = depositRepo.getDepositById(depositId);
+ return new ResponseEntity<>(deposit, HttpStatus.OK);
+ }
+
+ public ResponseEntity createDeposit(Deposit deposit, Long accountId) {
+ //TODO: Check if account exists
+ try {
+ deposit.setAccount(accountRepo.findById(accountId).orElseThrow(Exception::new));
+ Deposit newDeposit = depositRepo.save(deposit);
+ return new ResponseEntity<>(newDeposit, HttpStatus.CREATED);
+ } catch (Exception e) {
+ return new ResponseEntity<>(new Deposit(), HttpStatus.NOT_FOUND);
+
+ }
+
+ }
+
+ public ResponseEntity updateDeposit(Deposit deposit, Long depositId) {
+ //TODO: check if deposit exists by that id
+ Deposit updateDeposit = depositRepo.getDepositById(depositId);
+ deposit = depositRepo.save(updateDeposit);
+ return new ResponseEntity<>(deposit, HttpStatus.OK);
+ }
+
+ public ResponseEntity deleteDepositById(Long depositId) {
+ depositRepo.deleteById(depositId);
+ return new ResponseEntity(HttpStatus.OK);
+ }
+}
diff --git a/src/main/java/io/zipcoder/service/implementations/WithdrawalServiceImpl.java b/src/main/java/io/zipcoder/service/implementations/WithdrawalServiceImpl.java
new file mode 100644
index 0000000..a65d831
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/implementations/WithdrawalServiceImpl.java
@@ -0,0 +1,59 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Withdrawal;
+import io.zipcoder.repository.WithdrawalRepository;
+import io.zipcoder.service.interfaces.WithdrawalService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@Service
+public class WithdrawalServiceImpl implements WithdrawalService {
+
+ private WithdrawalRepository withdrawalRepo;
+
+ @Autowired
+ public WithdrawalServiceImpl(WithdrawalRepository withdrawalRepo) {
+ this.withdrawalRepo = withdrawalRepo;
+ }
+
+ public ResponseEntity> getAllWithdrawalsByAccountId(Long accountId) {
+ Iterable allWithdrawals = withdrawalRepo.findAllByAccount_Id(accountId);
+ return new ResponseEntity<>(allWithdrawals, HttpStatus.OK);
+ }
+
+ public ResponseEntity getWithdrawalById(Long withdrawalId) {
+ Withdrawal singleWithdrawal = withdrawalRepo.getById(withdrawalId);
+ return new ResponseEntity<>(singleWithdrawal, HttpStatus.OK);
+ }
+
+ public ResponseEntity createWithdrawal(Withdrawal withdrawal, Long accountId) {
+ withdrawal = withdrawalRepo.save(withdrawal);
+// HttpHeaders responseHeaders = new HttpHeaders();
+// URI newPollUri = ServletUriComponentsBuilder
+// .fromCurrentRequest()
+// .path("/accounts/{id}/withdrawal")
+// .buildAndExpand(withdrawal.getId())
+// .toUri();
+// responseHeaders.setLocation(newPollUri);
+ return new ResponseEntity<>(withdrawal, HttpStatus.CREATED);
+ }
+
+ public ResponseEntity updateWithdrawal(Withdrawal withdrawal, Long withdrawalId) {
+ Withdrawal w = withdrawalRepo.save(withdrawal);
+ return new ResponseEntity<>(w, HttpStatus.OK);
+ }
+
+ public ResponseEntity deleteWithdrawalById(Long withdrawalId) {
+ withdrawalRepo.deleteById(withdrawalId);
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
+}
+
diff --git a/src/main/java/io/zipcoder/service/interfaces/AccountService.java b/src/main/java/io/zipcoder/service/interfaces/AccountService.java
new file mode 100644
index 0000000..83bbe6a
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/interfaces/AccountService.java
@@ -0,0 +1,25 @@
+package io.zipcoder.service.interfaces;
+
+import io.zipcoder.domain.Account;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+public interface AccountService {
+ ResponseEntity> getAllAccounts();
+
+ ResponseEntity getAccountById(Long accountId);
+
+ ResponseEntity> getAccountsByCustomerId(Long customerId);
+
+ ResponseEntity createAccount(Account account, Long customerId);
+
+ ResponseEntity updateAccount(Account account, Long accountId);
+
+ ResponseEntity deleteAccountById(Long accountId);
+}
diff --git a/src/main/java/io/zipcoder/service/interfaces/BillService.java b/src/main/java/io/zipcoder/service/interfaces/BillService.java
new file mode 100644
index 0000000..8e66375
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/interfaces/BillService.java
@@ -0,0 +1,24 @@
+package io.zipcoder.service.interfaces;
+
+import io.zipcoder.domain.Bill;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.interfaces
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface BillService {
+ ResponseEntity> getBillsByAccountId(Long accountId);
+
+ ResponseEntity getBillById(Long id);
+
+ ResponseEntity> getBillsByCustomerId(Long customerId);
+
+ ResponseEntity createBill(Bill bill, Long accountId);
+
+ ResponseEntity updateBill(Bill bill, Long billId);
+
+ ResponseEntity deleteBillById(Long billId);
+}
diff --git a/src/main/java/io/zipcoder/service/interfaces/CustomerService.java b/src/main/java/io/zipcoder/service/interfaces/CustomerService.java
new file mode 100644
index 0000000..54558c9
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/interfaces/CustomerService.java
@@ -0,0 +1,24 @@
+package io.zipcoder.service.interfaces;
+
+import io.zipcoder.domain.Customer;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.interfaces
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface CustomerService {
+ ResponseEntity getCustomerByAccountId(Long accountId);
+
+ ResponseEntity> getAllCustomers();
+
+ ResponseEntity getCustomerById(Long customerId);
+
+ ResponseEntity createCustomer(Customer customer);
+
+ ResponseEntity updateCustomer(Customer customer, Long customerId);
+
+ ResponseEntity deleteCustomerById(Long customerId);
+}
diff --git a/src/main/java/io/zipcoder/service/interfaces/DepositService.java b/src/main/java/io/zipcoder/service/interfaces/DepositService.java
new file mode 100644
index 0000000..cddb507
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/interfaces/DepositService.java
@@ -0,0 +1,22 @@
+package io.zipcoder.service.interfaces;
+
+import io.zipcoder.domain.Deposit;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.interfaces
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface DepositService {
+ ResponseEntity> getAllDepositsByAccountId(Long accountId);
+
+ ResponseEntity getDepositById(Long depositId);
+
+ ResponseEntity createDeposit(Deposit deposit, Long accountId);
+
+ ResponseEntity updateDeposit(Deposit deposit, Long depositId);
+
+ ResponseEntity deleteDepositById(Long depositId);
+}
diff --git a/src/main/java/io/zipcoder/service/interfaces/WithdrawalService.java b/src/main/java/io/zipcoder/service/interfaces/WithdrawalService.java
new file mode 100644
index 0000000..6349ce9
--- /dev/null
+++ b/src/main/java/io/zipcoder/service/interfaces/WithdrawalService.java
@@ -0,0 +1,22 @@
+package io.zipcoder.service.interfaces;
+
+import io.zipcoder.domain.Withdrawal;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.interfaces
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+public interface WithdrawalService {
+ ResponseEntity> getAllWithdrawalsByAccountId(Long accountId);
+
+ ResponseEntity getWithdrawalById(Long withdrawalId);
+
+ ResponseEntity createWithdrawal(Withdrawal withdrawal, Long accountId);
+
+ ResponseEntity updateWithdrawal(Withdrawal withdrawal, Long withdrawalId);
+
+ ResponseEntity deleteWithdrawalById(Long withdrawalId);
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml
similarity index 100%
rename from src/main/resources/application.properties
rename to src/main/resources/application.yml
diff --git a/src/test/java/io/zipcoder/ZcwbankApplicationTests.java b/src/test/java/io/zipcoder/ZcwbankApplicationTests.java
index 846d527..1833dc5 100644
--- a/src/test/java/io/zipcoder/ZcwbankApplicationTests.java
+++ b/src/test/java/io/zipcoder/ZcwbankApplicationTests.java
@@ -9,8 +9,8 @@
@SpringBootTest
public class ZcwbankApplicationTests {
- @Test
- public void contextLoads() {
- }
+ @Test
+ public void contextLoads() {
+ }
}
diff --git a/src/test/java/io/zipcoder/controller/AccountControllerIntegrationTest.java b/src/test/java/io/zipcoder/controller/AccountControllerIntegrationTest.java
new file mode 100644
index 0000000..76db72c
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/AccountControllerIntegrationTest.java
@@ -0,0 +1,125 @@
+package io.zipcoder.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static java.util.Collections.singletonList;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/11/18
+ */
+
+@SuppressWarnings("unchecked")
+@RunWith(SpringRunner.class)
+@WebMvcTest(AccountController.class)
+public class AccountControllerIntegrationTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private AccountController accountController;
+
+ private Account mockAccount;
+ private ObjectMapper om = new ObjectMapper();
+
+ @Before
+ public void setup() {
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+ }
+
+ @Test
+ public void getAllAccounts() throws Exception {
+ Iterable accounts = singletonList(mockAccount);
+ ResponseEntity> response = new ResponseEntity<>(accounts, OK);
+
+ given(accountController.getAllAccounts())
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getAccountById() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockAccount, OK);
+
+ given(accountController.getAccountById(mockAccount.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getAccountsByCustomerId() throws Exception {
+ Iterable accounts = singletonList(mockAccount);
+ ResponseEntity> response = new ResponseEntity<>(accounts, OK);
+
+ given(accountController.getAccountsByCustomerId(mockAccount.getCustomer().getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/customers/1/accounts")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void createAccount() throws Exception {
+ given(accountController.createAccount(mockAccount, mockAccount.getCustomer().getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockAccount);
+ mockMvc.perform(
+ post("/customers/1/accounts")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void updateAccount() throws Exception {
+ given(accountController.updateAccount(mockAccount, mockAccount.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockAccount);
+ mockMvc.perform(
+ put("/accounts/1")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void deleteAccountById() throws Exception {
+ mockMvc.perform(delete("/accounts/1"))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/AccountControllerTest.java b/src/test/java/io/zipcoder/controller/AccountControllerTest.java
new file mode 100644
index 0000000..7818add
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/AccountControllerTest.java
@@ -0,0 +1,127 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.service.interfaces.AccountService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+@RunWith(SpringRunner.class)
+public class AccountControllerTest {
+
+ @Mock
+ private AccountService accountService;
+
+ @InjectMocks
+ private AccountController accountController;
+
+ private Account mockAccount;
+ private Customer mockCustomer;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+ }
+
+ @Test
+ public void getAllAccounts() {
+ Iterable accounts = singletonList(mockAccount);
+ ResponseEntity> expected = new ResponseEntity<>(accounts, OK);
+ given(accountService.getAllAccounts())
+ .willReturn(expected);
+
+ ResponseEntity> actual = accountController.getAllAccounts();
+
+ verify(accountService).getAllAccounts();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAccountById() {
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, OK);
+ given(accountController.getAccountById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = accountController.getAccountById(mockAccount.getId());
+
+ verify(accountService).getAccountById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAccountsByCustomerId() {
+ Iterable accounts = singletonList(mockAccount);
+ ResponseEntity> expected = new ResponseEntity<>(accounts, OK);
+ given(accountService.getAccountsByCustomerId(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity> actual = accountController.getAccountsByCustomerId(mockAccount.getCustomer().getId());
+
+ verify(accountService).getAccountsByCustomerId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createAccount() {
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, CREATED);
+ given(accountService.createAccount(any(Account.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = accountController.createAccount(mockAccount, mockAccount.getCustomer().getId());
+
+ verify(accountService).createAccount(any(Account.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAccount() {
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, OK);
+ given(accountService.updateAccount(any(Account.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = accountController.updateAccount(mockAccount, mockAccount.getId());
+
+ verify(accountService).updateAccount(any(Account.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteAccountById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ given(accountService.deleteAccountById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = accountController.deleteAccountById(mockAccount.getId());
+
+ verify(accountService).deleteAccountById(anyLong());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/BillControllerIntegrationTest.java b/src/test/java/io/zipcoder/controller/BillControllerIntegrationTest.java
new file mode 100644
index 0000000..f488873
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/BillControllerIntegrationTest.java
@@ -0,0 +1,139 @@
+package io.zipcoder.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Bill;
+import io.zipcoder.domain.Customer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static java.util.Collections.singletonList;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/12/18
+ */
+
+@SuppressWarnings("unchecked")
+@RunWith(SpringRunner.class)
+@WebMvcTest(BillController.class)
+public class BillControllerIntegrationTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private BillController billController;
+
+ private Bill mockBill;
+ private Account mockAccount;
+
+ private ObjectMapper om = new ObjectMapper();
+
+ @Before
+ public void setUp() {
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+
+ mockBill = new Bill();
+ mockBill.setId(1L);
+ mockBill.setAccount(mockAccount);
+ mockBill.setStatus("OVERDUE_AF");
+ }
+
+ @Test
+ public void getBillsByAccountId() throws Exception {
+ Iterable bills = singletonList(mockBill);
+ ResponseEntity> response = new ResponseEntity<>(bills, OK);
+
+ given(billController.getBillsByAccountId(mockAccount.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts/1/bills")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getBillById() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockBill, OK);
+
+ given(billController.getBillById(mockBill.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/bills/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getBillsByCustomerId() throws Exception {
+ Iterable bills = singletonList(mockBill);
+ ResponseEntity> response = new ResponseEntity<>(bills, OK);
+
+ given(billController.getBillsByCustomerId(mockAccount.getCustomer().getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/customers/1/bills")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void createBill() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockBill, CREATED);
+
+ given(billController.createBill(mockBill, mockAccount.getId()))
+ .willReturn(response);
+
+ String body = om.writeValueAsString(mockBill);
+
+ mockMvc.perform(
+ post("/accounts/1/bills")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void updateBill() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockBill, OK);
+
+ given(billController.updateBill(mockBill, mockBill.getId()))
+ .willReturn(response);
+
+ String body = om.writeValueAsString(mockBill);
+
+ mockMvc.perform(
+ put("/bills/1")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void deleteBillById() throws Exception {
+ mockMvc.perform(delete("/bills/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/BillControllerTest.java b/src/test/java/io/zipcoder/controller/BillControllerTest.java
new file mode 100644
index 0000000..cb7f43e
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/BillControllerTest.java
@@ -0,0 +1,129 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Bill;
+import io.zipcoder.service.interfaces.BillService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+public class BillControllerTest {
+
+ @Mock
+ private BillService billService;
+
+ @InjectMocks
+ private BillController billController;
+
+ private Bill mockBill;
+ private Account mockAccount;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+
+ mockBill = new Bill();
+ mockBill.setId(1L);
+ mockBill.setAccount(mockAccount);
+
+ }
+
+ @Test
+ public void testGetBillsByAccountId() {
+ Iterable bills = singletonList(mockBill);
+ ResponseEntity> expected = new ResponseEntity<>(bills, OK);
+ given(billService.getBillsByAccountId(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity> actual = billController.getBillsByAccountId(mockAccount.getId());
+
+ verify(billService).getBillsByAccountId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testGetBillById() {
+ ResponseEntity expected = new ResponseEntity<>(mockBill, OK);
+ given(billService.getBillById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = billController.getBillById(mockBill.getId());
+
+ verify(billService).getBillById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testGetBillsByCustomerId() {
+ Iterable bills = singletonList(mockBill);
+ ResponseEntity> expected = new ResponseEntity<>(bills, OK);
+ given(billService.getBillsByCustomerId(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity> actual = billController.getBillsByCustomerId(1L);
+
+ verify(billService).getBillsByCustomerId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testCreateBill() {
+ ResponseEntity expected = new ResponseEntity<>(mockBill, CREATED);
+ given(billService.createBill(any(Bill.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = billController.createBill(mockBill, mockAccount.getId());
+
+ verify(billService).createBill(any(Bill.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testUpdateBill() {
+ ResponseEntity expected = new ResponseEntity<>(mockBill, OK);
+ given(billService.updateBill(any(Bill.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = billController.updateBill(mockBill, mockBill.getId());
+
+ verify(billService).updateBill(any(Bill.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testDeleteById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ given(billService.deleteBillById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = billController.deleteBillById(mockBill.getId());
+
+ verify(billService).deleteBillById(mockBill.getId());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/CustomerControllerIntegrationTest.java b/src/test/java/io/zipcoder/controller/CustomerControllerIntegrationTest.java
new file mode 100644
index 0000000..7780bbb
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/CustomerControllerIntegrationTest.java
@@ -0,0 +1,123 @@
+package io.zipcoder.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static java.util.Collections.singletonList;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/12/18
+ */
+
+@SuppressWarnings("unchecked")
+@RunWith(SpringRunner.class)
+@WebMvcTest(CustomerController.class)
+public class CustomerControllerIntegrationTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private CustomerController customerController;
+
+ private Account mockAccount;
+ private Customer mockCustomer;
+ private ObjectMapper om = new ObjectMapper();
+
+ @Before
+ public void setUp() {
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+
+ mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+ mockCustomer.setAccounts(singletonList(mockAccount));
+ }
+
+ @Test
+ public void getCustomerByAccountId() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockCustomer, OK);
+
+ given(customerController.getCustomerByAccountId(mockAccount.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts/1/customer")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getAllCustomers() throws Exception {
+ Iterable customers = singletonList(mockCustomer);
+ ResponseEntity> response = new ResponseEntity<>(customers, OK);
+
+ given(customerController.getAllCustomers())
+ .willReturn(response);
+
+ mockMvc.perform(get("/customers")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getCustomerById() throws Exception {
+ given(customerController.getCustomerByAccountId(mockCustomer.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ mockMvc.perform(get("/customers/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void createCustomer() throws Exception {
+ given(customerController.createCustomer(mockCustomer))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockCustomer);
+ mockMvc.perform(
+ post("/customers")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void updateCustomer() throws Exception {
+ given(customerController.updateCustomer(mockCustomer, mockCustomer.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockCustomer);
+ mockMvc.perform(
+ put("/customers/1")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void deleteCustomer() throws Exception {
+ mockMvc.perform(delete("/customers/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/CustomerControllerTest.java b/src/test/java/io/zipcoder/controller/CustomerControllerTest.java
new file mode 100644
index 0000000..1e832cd
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/CustomerControllerTest.java
@@ -0,0 +1,127 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.service.interfaces.CustomerService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+public class CustomerControllerTest {
+
+ @Mock
+ private CustomerService customerService;
+
+ @InjectMocks
+ private CustomerController customerController;
+
+ private Customer mockCustomer;
+ private Account mockAccount;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+ }
+
+ @Test
+ public void getCustomerByAccountId() {
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ given(customerService.getCustomerByAccountId(mockCustomer.getId()))
+ .willReturn(expected);
+
+ ResponseEntity actual = customerController.getCustomerByAccountId(mockAccount.getId());
+
+ verify(customerService).getCustomerByAccountId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAllCustomers() {
+ Iterable customers = singletonList(mockCustomer);
+ ResponseEntity> expected = new ResponseEntity<>(customers, OK);
+ given(customerService.getAllCustomers())
+ .willReturn(expected);
+
+ ResponseEntity> actual = customerController.getAllCustomers();
+
+ verify(customerService).getAllCustomers();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getCustomerById() {
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ given(customerService.getCustomerById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = customerController.getCustomerById(mockCustomer.getId());
+
+ verify(customerService).getCustomerById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createCustomer() {
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, CREATED);
+ given(customerService.createCustomer(any(Customer.class)))
+ .willReturn(expected);
+
+ ResponseEntity actual = customerController.createCustomer(mockCustomer);
+
+ verify(customerService).createCustomer(any(Customer.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateCustomer() {
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ given(customerService.updateCustomer(any(Customer.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = customerController.updateCustomer(mockCustomer, mockCustomer.getId());
+
+ verify(customerService).updateCustomer(any(Customer.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteCustomerById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ given(customerService.deleteCustomerById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = customerController.deleteCustomer(mockCustomer.getId());
+
+ verify(customerService).deleteCustomerById(anyLong());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/DepositControllerIntegrationTest.java b/src/test/java/io/zipcoder/controller/DepositControllerIntegrationTest.java
new file mode 100644
index 0000000..1c45184
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/DepositControllerIntegrationTest.java
@@ -0,0 +1,115 @@
+package io.zipcoder.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Deposit;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static java.util.Collections.singletonList;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/12/18
+ */
+
+@SuppressWarnings("unchecked")
+@RunWith(SpringRunner.class)
+@WebMvcTest(DepositController.class)
+public class DepositControllerIntegrationTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private DepositController depositController;
+
+ private Deposit mockDeposit;
+ private Account mockAccount;
+
+ private ObjectMapper om = new ObjectMapper();
+
+ @Before
+ public void setUp() {
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+
+ mockDeposit = new Deposit();
+ mockDeposit.setId(1L);
+
+
+ }
+
+ @Test
+ public void getAllDepositsByAccountId() throws Exception {
+ Iterable deposits = singletonList(mockDeposit);
+ ResponseEntity> response = new ResponseEntity<>(deposits, OK);
+
+ given(depositController.getAllDepositsByAccountId(mockAccount.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts/1/deposits")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getDepositById() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockDeposit, OK);
+
+ given(depositController.getDepositById(mockDeposit.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/deposits/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void createDeposit() throws Exception {
+ given(depositController.createDeposit(mockDeposit, mockAccount.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockDeposit);
+ mockMvc.perform(
+ post("/accounts/1/deposits")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void updateDeposit() throws Exception {
+ given(depositController.updateDeposit(mockDeposit, mockDeposit.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ String body = om.writeValueAsString(mockDeposit);
+ mockMvc.perform(
+ put("/deposits/1")
+ .contentType(APPLICATION_JSON)
+ .content(body))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void deleteDepositById() throws Exception {
+ mockMvc.perform(delete("/deposits/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/DepositControllerTest.java b/src/test/java/io/zipcoder/controller/DepositControllerTest.java
new file mode 100644
index 0000000..774fddf
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/DepositControllerTest.java
@@ -0,0 +1,120 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.domain.Deposit;
+import io.zipcoder.service.interfaces.DepositService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+public class DepositControllerTest {
+
+ @Mock
+ private DepositService depositService;
+
+ @InjectMocks
+ private DepositController depositController;
+
+ private Account mockAccount;
+ private Deposit mockDeposit;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+
+ mockDeposit = new Deposit();
+ mockDeposit.setId(1L);
+ mockDeposit.setAccount(mockAccount);
+ }
+
+ @Test
+ public void getAllDepositsByAccountIdTest() {
+ Iterable deposits = singletonList(mockDeposit);
+ ResponseEntity> expected = new ResponseEntity<>(deposits, HttpStatus.OK);
+ given(depositService.getAllDepositsByAccountId(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity> actual = depositController.getAllDepositsByAccountId(mockAccount.getId());
+
+ verify(depositService).getAllDepositsByAccountId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getDepositByIdTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.OK);
+ given(depositService.getDepositById(369L))
+ .willReturn(expected);
+
+ ResponseEntity actual = depositController.getDepositById(369L);
+
+ verify(depositService).getDepositById(369L);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createDepositTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.CREATED);
+ given(depositService.createDeposit(any(Deposit.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = depositController.createDeposit(mockDeposit, mockAccount.getId());
+
+ verify(depositService).createDeposit(any(Deposit.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateDepositTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.OK);
+ given(depositService.updateDeposit(any(Deposit.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = depositController.updateDeposit(mockDeposit, mockDeposit.getId());
+
+ verify(depositService).updateDeposit(any(Deposit.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteDepositById() {
+ ResponseEntity expected = new ResponseEntity(HttpStatus.OK);
+ given(depositService.deleteDepositById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = depositController.deleteDepositById(mockDeposit.getId());
+
+ verify(depositService).deleteDepositById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/WithdrawalControllerIntegrationTest.java b/src/test/java/io/zipcoder/controller/WithdrawalControllerIntegrationTest.java
new file mode 100644
index 0000000..e60a1b6
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/WithdrawalControllerIntegrationTest.java
@@ -0,0 +1,113 @@
+package io.zipcoder.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Withdrawal;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static java.util.Collections.singletonList;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/12/18
+ */
+
+@SuppressWarnings("unchecked")
+@RunWith(SpringRunner.class)
+@WebMvcTest(WithdrawalController.class)
+public class WithdrawalControllerIntegrationTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @MockBean
+ private WithdrawalController withdrawalController;
+
+ private Withdrawal mockWithdrawal;
+ private Account mockAccount;
+
+ private String mockWithdrawalJson;
+
+ @Before
+ public void setUp() throws Exception {
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+
+ mockWithdrawal = new Withdrawal();
+ mockWithdrawal.setId(1L);
+
+ mockWithdrawalJson = new ObjectMapper().writeValueAsString(mockWithdrawal);
+ }
+
+ @Test
+ public void getAllWithdrawalsByAccountId() throws Exception {
+ Iterable withdrawals = singletonList(mockWithdrawal);
+ ResponseEntity> response = new ResponseEntity<>(withdrawals, OK);
+
+ given(withdrawalController.getAllWithdrawalsByAccountId(mockAccount.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/accounts/1/withdrawals")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void getWithdrawalById() throws Exception {
+ ResponseEntity response = new ResponseEntity<>(mockWithdrawal, OK);
+
+ given(withdrawalController.getWithdrawalById(mockWithdrawal.getId()))
+ .willReturn(response);
+
+ mockMvc.perform(get("/withdrawals/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void createWithdrawal() throws Exception {
+ given(withdrawalController.createWithdrawal(mockWithdrawal, mockAccount.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ mockMvc.perform(
+ post("/accounts/1/withdrawal")
+ .contentType(APPLICATION_JSON)
+ .content(mockWithdrawalJson))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void updateWithdrawal() throws Exception {
+ given(withdrawalController.updateWithdrawal(mockWithdrawal, mockWithdrawal.getId()))
+ .willReturn(mock(ResponseEntity.class));
+
+ mockMvc.perform(
+ put("/withdrawals/1")
+ .contentType(APPLICATION_JSON)
+ .content(mockWithdrawalJson))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void deleteWithdrawalById() throws Exception {
+ mockMvc.perform(delete("/withdrawals/1")
+ .contentType(APPLICATION_JSON))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/controller/WithdrawalControllerTest.java b/src/test/java/io/zipcoder/controller/WithdrawalControllerTest.java
new file mode 100644
index 0000000..5e5d760
--- /dev/null
+++ b/src/test/java/io/zipcoder/controller/WithdrawalControllerTest.java
@@ -0,0 +1,120 @@
+package io.zipcoder.controller;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.domain.Withdrawal;
+import io.zipcoder.service.interfaces.WithdrawalService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.controller
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+public class WithdrawalControllerTest {
+
+ @Mock
+ private WithdrawalService withdrawalService;
+
+ @InjectMocks
+ private WithdrawalController withdrawalController;
+
+ private Account mockAccount;
+ private Withdrawal mockWithdrawal;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+
+ mockWithdrawal = new Withdrawal();
+ mockWithdrawal.setId(1L);
+ mockWithdrawal.setAccount(mockAccount);
+ }
+
+ @Test
+ public void getAllWithdrawalsByAccountIdTest() {
+ Iterable withdrawals = singletonList(mockWithdrawal);
+ ResponseEntity> expected = new ResponseEntity<>(withdrawals, HttpStatus.OK);
+ given(withdrawalService.getAllWithdrawalsByAccountId(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity> actual = withdrawalController.getAllWithdrawalsByAccountId(mockAccount.getId());
+
+ verify(withdrawalService).getAllWithdrawalsByAccountId(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getWithdrawalByIdTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, HttpStatus.OK);
+ given(withdrawalService.getWithdrawalById(369L))
+ .willReturn(expected);
+
+ ResponseEntity actual = withdrawalController.getWithdrawalById(369L);
+
+ verify(withdrawalService).getWithdrawalById(369L);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createWithdrawalTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, HttpStatus.CREATED);
+ given(withdrawalService.createWithdrawal(any(Withdrawal.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = withdrawalController.createWithdrawal(mockWithdrawal, mockAccount.getId());
+
+ verify(withdrawalService).createWithdrawal(any(Withdrawal.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateWithdrawalTest() {
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, HttpStatus.OK);
+ given(withdrawalService.updateWithdrawal(any(Withdrawal.class), anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = withdrawalController.updateWithdrawal(mockWithdrawal, mockWithdrawal.getId());
+
+ verify(withdrawalService).updateWithdrawal(any(Withdrawal.class), anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteWithdrawalById() {
+ ResponseEntity expected = new ResponseEntity(HttpStatus.OK);
+ given(withdrawalService.deleteWithdrawalById(anyLong()))
+ .willReturn(expected);
+
+ ResponseEntity actual = withdrawalController.deleteWithdrawalById(mockWithdrawal.getId());
+
+ verify(withdrawalService).deleteWithdrawalById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/repository/AccountRepositoryTest.java b/src/test/java/io/zipcoder/repository/AccountRepositoryTest.java
new file mode 100644
index 0000000..27b6b55
--- /dev/null
+++ b/src/test/java/io/zipcoder/repository/AccountRepositoryTest.java
@@ -0,0 +1,52 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/13/18
+ */
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = NONE)
+public class AccountRepositoryTest {
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Autowired
+ private AccountRepository accountRepo;
+
+ @Test
+ public void whenFindAllByCustomer_Id() {
+ // given
+ Customer mockCustomer = new Customer();
+ Long customerId = entityManager.persistAndGetId(mockCustomer, Long.class);
+
+ Account account = new Account();
+ account.setCustomer(mockCustomer);
+
+ entityManager.persist(account);
+ entityManager.flush();
+
+ // when
+ Iterable foundAccounts = accountRepo.findAllByCustomer_Id(customerId);
+
+ // then
+ assertThat(foundAccounts).contains(account);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/repository/AddressRepositoryTest.java b/src/test/java/io/zipcoder/repository/AddressRepositoryTest.java
new file mode 100644
index 0000000..0375496
--- /dev/null
+++ b/src/test/java/io/zipcoder/repository/AddressRepositoryTest.java
@@ -0,0 +1,54 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Address;
+import io.zipcoder.domain.Customer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = NONE)
+public class AddressRepositoryTest {
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Autowired
+ private AddressRepository addressRepository;
+
+ @Test
+ public void testAddress() {
+
+ Address address = new Address();
+ address.setCity("San Fransisco");
+ address.setState("California");
+ address.setStreet_name("Fake St");
+ address.setStreet_number("123");
+
+ Customer customer = new Customer();
+ Long customerId = entityManager.persistAndGetId(customer, Long.class);
+ customer.setAddress(address);
+
+ address.setCustomer(customer);
+ entityManager.persistAndFlush(address);
+
+ Address foundAddress = addressRepository.findByCustomer_Id(customerId);
+
+ assertEquals(address, foundAddress);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/repository/BillRepositoryTest.java b/src/test/java/io/zipcoder/repository/BillRepositoryTest.java
new file mode 100644
index 0000000..08d0e94
--- /dev/null
+++ b/src/test/java/io/zipcoder/repository/BillRepositoryTest.java
@@ -0,0 +1,74 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Bill;
+import io.zipcoder.domain.Customer;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/13/18
+ */
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = NONE)
+public class BillRepositoryTest {
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Autowired
+ private BillRepository billRepository;
+
+ @Test
+ public void findAllByAccount_Id() {
+ //given
+ Account testAccount = new Account();
+ Long accountId = entityManager.persistAndGetId(testAccount, Long.class);
+
+ Bill bill = new Bill();
+ bill.setAccount(testAccount);
+
+ entityManager.persist(bill);
+ entityManager.flush();
+
+ //when
+ Iterable foundBill = billRepository.findAllByAccount_Id(accountId);
+
+ //then
+ assertThat(foundBill).contains(bill);
+ }
+
+ @Test
+ public void findAllByAccount_Customer_Id() {
+ //given
+ Customer testCustomer = new Customer();
+ Long customerId = entityManager.persistAndGetId(testCustomer, Long.class);
+
+ Account testAccount = new Account();
+ testAccount.setCustomer(testCustomer);
+ entityManager.persist(testAccount);
+
+ Bill testBill = new Bill();
+ testBill.setAccount(testAccount);
+ entityManager.persistAndFlush(testBill);
+
+ //when
+ Iterable foundBills = billRepository.findAllByAccount_Customer_Id(customerId);
+
+ //then
+ assertThat(foundBills).contains(testBill);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/repository/DepositRepositoryTest.java b/src/test/java/io/zipcoder/repository/DepositRepositoryTest.java
new file mode 100644
index 0000000..0907b1c
--- /dev/null
+++ b/src/test/java/io/zipcoder/repository/DepositRepositoryTest.java
@@ -0,0 +1,58 @@
+package io.zipcoder.repository;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Deposit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace.NONE;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.repository
+ * author: https://github.com/vvmk
+ * date: 4/14/18
+ */
+
+@RunWith(SpringRunner.class)
+@DataJpaTest
+@AutoConfigureTestDatabase(replace = NONE)
+public class DepositRepositoryTest {
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Autowired
+ private DepositRepository depositRepo;
+
+ @Test
+ public void getDepositsByAccount_Id() {
+ Account testAccount = new Account();
+ Long accountId = entityManager.persistAndGetId(testAccount, Long.class);
+
+ Deposit testDeposit = new Deposit();
+ testDeposit.setAccount(testAccount);
+ entityManager.persistAndFlush(testDeposit);
+
+ Iterable foundDeposits = depositRepo.getDepositsByAccount_Id(accountId);
+
+ assertThat(foundDeposits).contains(testDeposit);
+ }
+
+ @Test
+ public void getDepositById() {
+ Deposit expected = new Deposit();
+ Long depositId = entityManager.persistAndGetId(expected, Long.class);
+
+ Deposit actual = depositRepo.getDepositById(depositId);
+
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/service/implementations/AccountServiceImplTest.java b/src/test/java/io/zipcoder/service/implementations/AccountServiceImplTest.java
new file mode 100644
index 0000000..2cf6f2a
--- /dev/null
+++ b/src/test/java/io/zipcoder/service/implementations/AccountServiceImplTest.java
@@ -0,0 +1,131 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.CustomerRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Optional;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/13/18
+ */
+
+@RunWith(SpringRunner.class)
+public class AccountServiceImplTest {
+
+ @InjectMocks
+ private AccountServiceImpl accountService;
+
+ @Mock
+ private AccountRepository accountRepo;
+
+ @Mock
+ private CustomerRepository customerRepo;
+
+ private Account mockAccount;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+ }
+
+ @Test
+ public void getAccountById() {
+ given(accountRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockAccount));
+
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, OK);
+ ResponseEntity actual = accountService.getAccountById(mockAccount.getId());
+
+ verify(accountRepo).findById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAccountsByCustomerId() {
+ Iterable accounts = singletonList(mockAccount);
+ given(accountRepo.findAllByCustomer_Id(anyLong()))
+ .willReturn(accounts);
+
+ ResponseEntity> expected = new ResponseEntity<>(accounts, OK);
+ ResponseEntity> actual = accountService.getAccountsByCustomerId(mockAccount.getCustomer().getId());
+
+ verify(accountRepo).findAllByCustomer_Id(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createAccount() {
+ given(customerRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockAccount.getCustomer()));
+ given(accountRepo.save(any(Account.class)))
+ .willReturn(mockAccount);
+
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, CREATED);
+ ResponseEntity actual = accountService.createAccount(mockAccount, mockAccount.getCustomer().getId());
+
+ verify(accountRepo).save(any(Account.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateAccount() {
+ given(accountRepo.save(any(Account.class)))
+ .willReturn(mockAccount);
+
+ ResponseEntity expected = new ResponseEntity<>(mockAccount, OK);
+ ResponseEntity actual = accountService.updateAccount(mockAccount, mockAccount.getId());
+
+ verify(accountRepo).save(any(Account.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteAccountById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ ResponseEntity actual = accountService.deleteAccountById(mockAccount.getId());
+
+ verify(accountRepo).deleteById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAllAccounts() {
+ Iterable accounts = singletonList(mockAccount);
+ given(accountRepo.findAll())
+ .willReturn(accounts);
+
+ ResponseEntity expected = new ResponseEntity(accounts, OK);
+ ResponseEntity actual = accountService.getAllAccounts();
+
+ verify(accountRepo).findAll();
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/service/implementations/BillServiceImplTest.java b/src/test/java/io/zipcoder/service/implementations/BillServiceImplTest.java
new file mode 100644
index 0000000..85b9203
--- /dev/null
+++ b/src/test/java/io/zipcoder/service/implementations/BillServiceImplTest.java
@@ -0,0 +1,140 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Bill;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.BillRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Optional;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+@RunWith(SpringRunner.class)
+public class BillServiceImplTest {
+
+ @InjectMocks
+ private BillServiceImpl billService;
+
+ @Mock
+ private BillRepository billRepo;
+
+ @Mock
+ private AccountRepository accountRepo;
+
+ private Bill mockBill;
+ private Account mockAccount;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+
+ mockBill = new Bill();
+ mockBill.setId(1L);
+ mockBill.setAccount(mockAccount);
+ }
+
+ @Test
+ public void testGetBillsByAccountId() {
+ Iterable bills = singletonList(mockBill);
+ given(billRepo.findAllByAccount_Id(anyLong()))
+ .willReturn(bills);
+
+ ResponseEntity> expected = new ResponseEntity<>(bills, OK);
+ ResponseEntity> actual = billService.getBillsByAccountId(mockAccount.getId());
+
+ verify(billRepo).findAllByAccount_Id(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testGetBillById() {
+ given(billRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockBill));
+
+ ResponseEntity expected = new ResponseEntity<>(mockBill, OK);
+ ResponseEntity actual = billService.getBillById(mockBill.getId());
+
+ verify(billRepo).findById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testGetBillsByCustomerId() {
+ Iterable bills = singletonList(mockBill);
+ Long custId = mockAccount.getCustomer().getId();
+ given(billRepo.findAllByAccount_Customer_Id(anyLong()))
+ .willReturn(bills);
+
+ ResponseEntity> expected = new ResponseEntity<>(bills, OK);
+ ResponseEntity> actual = billService.getBillsByCustomerId(custId);
+
+ verify(billRepo).findAllByAccount_Customer_Id(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testCreateBill() {
+ given(accountRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockAccount));
+
+ given(billRepo.save(any(Bill.class)))
+ .willReturn(mockBill);
+
+ ResponseEntity expected = new ResponseEntity<>(mockBill, CREATED);
+ ResponseEntity actual = billService.createBill(mockBill, mockAccount.getId());
+
+ verify(billRepo).save(any(Bill.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testUpdateBill() {
+ given(billRepo.save(any(Bill.class)))
+ .willReturn(mockBill);
+
+ ResponseEntity expected = new ResponseEntity<>(mockBill, OK);
+ ResponseEntity actual = billService.updateBill(mockBill, mockBill.getId());
+
+ verify(billRepo).save(any(Bill.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testDeleteById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ ResponseEntity actual = billService.deleteBillById(mockBill.getId());
+
+ verify(billRepo).deleteById(mockBill.getId());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/service/implementations/CustomerServiceImplTest.java b/src/test/java/io/zipcoder/service/implementations/CustomerServiceImplTest.java
new file mode 100644
index 0000000..fe164a5
--- /dev/null
+++ b/src/test/java/io/zipcoder/service/implementations/CustomerServiceImplTest.java
@@ -0,0 +1,136 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.CustomerRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Optional;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/13/18
+ */
+
+@RunWith(SpringRunner.class)
+public class CustomerServiceImplTest {
+
+ @InjectMocks
+ private CustomerServiceImpl customerService;
+
+ @Mock
+ private CustomerRepository customerRepo;
+
+ @Mock
+ private AccountRepository accountRepo;
+
+ private Customer mockCustomer;
+ private Account mockAccount;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mockCustomer = new Customer();
+ mockCustomer.setId(1L);
+
+ mockAccount = new Account();
+ mockAccount.setId(1L);
+ mockAccount.setCustomer(mockCustomer);
+ }
+
+ @Test
+ public void getCustomerByAccountId() {
+ given(accountRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockAccount));
+
+ given(customerRepo.findById(mockCustomer.getId()))
+ .willReturn(Optional.of(mockCustomer));
+
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ ResponseEntity actual = customerService.getCustomerByAccountId(mockAccount.getId());
+
+ verify(accountRepo).findById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAllCustomers() {
+ Iterable customers = singletonList(mockCustomer);
+ given(customerRepo.findAll())
+ .willReturn(customers);
+
+ ResponseEntity> expected = new ResponseEntity<>(customers, OK);
+ ResponseEntity> actual = customerService.getAllCustomers();
+
+ verify(customerRepo).findAll();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getCustomerById() {
+ given(customerRepo.findById(anyLong()))
+ .willReturn(Optional.of(mockCustomer));
+
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ ResponseEntity actual = customerService.getCustomerById(mockCustomer.getId());
+
+ verify(customerRepo).findById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createCustomer() {
+ given(customerRepo.save(any(Customer.class)))
+ .willReturn(mockCustomer);
+
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, CREATED);
+ ResponseEntity actual = customerService.createCustomer(mockCustomer);
+
+ verify(customerRepo).save(any(Customer.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateCustomer() {
+ given(customerRepo.existsById(anyLong()))
+ .willReturn(true);
+
+ given(customerRepo.save(any(Customer.class)))
+ .willReturn(mockCustomer);
+
+ ResponseEntity expected = new ResponseEntity<>(mockCustomer, OK);
+ ResponseEntity actual = customerService.updateCustomer(mockCustomer, mockCustomer.getId());
+
+ verify(customerRepo).save(any(Customer.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteCustomerById() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ ResponseEntity actual = customerService.deleteCustomerById(mockCustomer.getId());
+
+ verify(customerRepo).deleteById(anyLong());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/service/implementations/DepositServiceImplTest.java b/src/test/java/io/zipcoder/service/implementations/DepositServiceImplTest.java
new file mode 100644
index 0000000..1c5e729
--- /dev/null
+++ b/src/test/java/io/zipcoder/service/implementations/DepositServiceImplTest.java
@@ -0,0 +1,121 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Customer;
+import io.zipcoder.domain.Deposit;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.DepositRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Optional;
+
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+
+
+@RunWith(SpringRunner.class)
+public class DepositServiceImplTest {
+
+ @InjectMocks// injects the made mocks into the deposit service
+ private DepositServiceImpl depositService;
+
+ @Mock // mock to be injected into depositService
+ private DepositRepository depositRepository;
+
+ @Mock
+ private AccountRepository accountRepository;
+
+ private Account mockAccount;
+ private Deposit mockDeposit;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this); //initializes fields annotated with Mockito annotations
+ Customer mockCustomer = new Customer();
+ mockCustomer.setId(369L);
+
+ mockAccount = new Account();
+ mockAccount.setId(369L);
+ mockAccount.setCustomer(mockCustomer);
+
+ mockDeposit = new Deposit();
+ mockDeposit.setId(369L);
+ mockDeposit.setAccount(mockAccount);
+ }
+
+ @Test
+ public void getAllDepositsByAccountIdTest() {
+ Iterable deposits = singletonList(mockDeposit);
+ given(depositRepository.getDepositsByAccount_Id(anyLong()))
+ .willReturn(deposits);
+ ResponseEntity> expected = new ResponseEntity<>(deposits, HttpStatus.OK);
+ ResponseEntity> actual = depositService.getAllDepositsByAccountId(mockAccount.getId());
+
+ verify(depositRepository).getDepositsByAccount_Id(anyLong());
+ assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void getDepositByIdTest() {
+ given(depositRepository.getDepositById(369L)).willReturn(mockDeposit);
+
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.OK);
+ ResponseEntity actual = depositService.getDepositById(369L);
+
+ verify(depositRepository).getDepositById(369L);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void createDepositTest() {
+ given(accountRepository.findById(anyLong())).willReturn(Optional.of(mockAccount));
+ given(depositRepository.save(any(Deposit.class))).willReturn(mockDeposit);// any allows flexible stubbing and verification
+
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.CREATED);
+ ResponseEntity actual = depositService.createDeposit(mockDeposit, mockAccount.getId());
+
+ verify(depositRepository).save(any(Deposit.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateDepositTest() {
+ given(depositRepository.getDepositById(anyLong())).willReturn(mockDeposit);
+ given(depositRepository.save(any(Deposit.class))).willReturn(mockDeposit);
+
+ ResponseEntity expected = new ResponseEntity<>(mockDeposit, HttpStatus.OK);
+ ResponseEntity actual = depositService.updateDeposit(mockDeposit, mockDeposit.getId());
+
+ verify(depositRepository).save(any(Deposit.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteDepositById() {
+ ResponseEntity expected = new ResponseEntity(HttpStatus.OK);
+ ResponseEntity actual = depositService.deleteDepositById(mockDeposit.getId());
+
+ verify(depositRepository).deleteById(anyLong());
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/service/implementations/WithdrawalServiceImplTest.java b/src/test/java/io/zipcoder/service/implementations/WithdrawalServiceImplTest.java
new file mode 100644
index 0000000..d4e449d
--- /dev/null
+++ b/src/test/java/io/zipcoder/service/implementations/WithdrawalServiceImplTest.java
@@ -0,0 +1,135 @@
+package io.zipcoder.service.implementations;
+
+import io.zipcoder.domain.Account;
+import io.zipcoder.domain.Withdrawal;
+import io.zipcoder.repository.AccountRepository;
+import io.zipcoder.repository.WithdrawalRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.springframework.http.HttpStatus.CREATED;
+import static org.springframework.http.HttpStatus.OK;
+
+/**
+ * project: zcwbank
+ * package: io.zipcoder.service.implementations
+ * author: https://github.com/vvmk
+ * date: 4/9/18
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class WithdrawalServiceImplTest {
+
+ @InjectMocks
+ WithdrawalServiceImpl withdrawalServiceImpl;
+
+ @Mock
+ WithdrawalRepository withdrawalRepoMock;
+
+ @Mock
+ AccountRepository accountRepoMock;
+
+ private Account mockAccount;
+ private Withdrawal mockWithdrawal;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+
+ mockAccount = new Account();
+ mockAccount.setId(4444L);
+
+ mockWithdrawal = new Withdrawal();
+ mockWithdrawal.setAmount(500.00);
+ mockWithdrawal.setId(666L);
+ mockWithdrawal.setAccount(mockAccount);
+ }
+
+ @Test
+ public void testGetAllWithdrawalByAccountId() {
+ // given
+ List withdrawals = new ArrayList<>();
+ withdrawals.add(mockWithdrawal);
+
+ given(withdrawalRepoMock.findAllByAccount_Id(anyLong()))
+ .willReturn(withdrawals);
+
+ // when
+ ResponseEntity> expected = new ResponseEntity<>(withdrawals, HttpStatus.OK);
+ ResponseEntity> actual = withdrawalServiceImpl.getAllWithdrawalsByAccountId(mockAccount.getId());
+
+ // then
+ verify(withdrawalRepoMock).findAllByAccount_Id(anyLong());
+ assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void testGetWithdrawalById() {
+ List withdrawals = new ArrayList<>();
+ withdrawals.add(mockWithdrawal);
+
+ given(withdrawalRepoMock.getById(anyLong()))
+ .willReturn(mockWithdrawal);
+
+ // when
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, HttpStatus.OK);
+ ResponseEntity actual = withdrawalServiceImpl.getWithdrawalById(mockWithdrawal.getId());
+
+ // then
+ verify(withdrawalRepoMock).getById(anyLong());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testCreateWithdrawal() {
+
+ given(withdrawalRepoMock.save(any(Withdrawal.class)))
+ .willReturn(mockWithdrawal);
+
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, CREATED);
+ ResponseEntity actual = withdrawalServiceImpl.createWithdrawal(mockWithdrawal, mockAccount.getId());
+
+ verify(withdrawalRepoMock).save(any(Withdrawal.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testUpdateWithdrawal() {
+ given(withdrawalRepoMock.save(any(Withdrawal.class)))
+ .willReturn(mockWithdrawal);
+
+ ResponseEntity expected = new ResponseEntity<>(mockWithdrawal, OK);
+ ResponseEntity actual = withdrawalServiceImpl.updateWithdrawal(mockWithdrawal, mockWithdrawal.getId());
+
+ verify(withdrawalRepoMock).save(any(Withdrawal.class));
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testDeleteWithdrawal() {
+ ResponseEntity expected = new ResponseEntity(OK);
+ ResponseEntity actual = withdrawalServiceImpl.deleteWithdrawalById(mockWithdrawal.getId());
+
+ verify(withdrawalRepoMock).deleteById(mockWithdrawal.getId());
+ assertEquals(expected, actual);
+ }
+
+
+}
\ No newline at end of file
diff --git a/zipperBankUML.png b/zipperBankUML.png
new file mode 100644
index 0000000..d2c8d7c
Binary files /dev/null and b/zipperBankUML.png differ