diff --git a/pom.xml b/pom.xml index 0a99788..84a3e94 100644 --- a/pom.xml +++ b/pom.xml @@ -21,10 +21,16 @@ UTF-8 UTF-8 - 1.7 + 1.8 + + junit + junit + 4.12 + test + org.springframework.boot spring-boot-starter-web @@ -44,11 +50,40 @@ runtime + + + mysql + mysql-connector-java + 5.1.6 + + + com.h2database + h2 + compile + + + org.mockito + mockito-core + 2.18.0 + javax.inject javax.inject 1 + + + org.springframework + spring-test + 4.3.13.RELEASE + test + + + org.springframework.boot + spring-boot-test-autoconfigure + 1.5.9.RELEASE + test + diff --git a/src/main/java/io/zipcoder/ZcwbankApplication.java b/src/main/java/io/zipcoder/ZcwbankApplication.java index 60df46b..e5d6466 100644 --- a/src/main/java/io/zipcoder/ZcwbankApplication.java +++ b/src/main/java/io/zipcoder/ZcwbankApplication.java @@ -2,6 +2,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; @SpringBootApplication public class ZcwbankApplication { @@ -9,4 +11,6 @@ public class ZcwbankApplication { 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..98ff6e6 --- /dev/null +++ b/src/main/java/io/zipcoder/controller/AccountController.java @@ -0,0 +1,51 @@ +package io.zipcoder.controller; + + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import io.zipcoder.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + + public AccountController(AccountService accountService){ + this.accountService = accountService; + } + + @RequestMapping(value = "/accounts", method = RequestMethod.GET) + public ResponseEntity getAllAccounts(){ + return accountService.getAllAccounts(); + } + + @RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.GET) + public ResponseEntity getAccountById(@PathVariable("accountId") Long accountId){ + return accountService.getAccountById(accountId); + } + + @RequestMapping(value = "/customers/{customerId}/accounts", method = RequestMethod.GET) + public ResponseEntity getAccountsForCustomer(@PathVariable("customerId") Long customerId){ + return accountService.getAccountsOfCustomer(customerId); + } + + @RequestMapping(value = "/customers/{customerId}/accounts", method = RequestMethod.POST) + public ResponseEntity createAccount(@PathVariable ("customerId") Long customerId, @RequestBody Account account){ + return accountService.createAccount(customerId, account); + } + + @RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.PUT) + public ResponseEntity updateAccount(@PathVariable("accountId") Long accountId, @RequestBody Account account){ + return accountService.updateAccount(account, accountId); + } + + @RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.DELETE) + public ResponseEntity deleteAccount(@PathVariable("accountId") Long accountId){ + return accountService.deleteAccount(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..23f86fd --- /dev/null +++ b/src/main/java/io/zipcoder/controller/BillController.java @@ -0,0 +1,53 @@ +package io.zipcoder.controller; + +import io.zipcoder.domain.Bill; +import io.zipcoder.service.BillService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +public class BillController { + + @Autowired + private BillService billService; + + public BillController() {} + + public BillController(BillService billService) { + this.billService = billService; + } + + @RequestMapping(value="/accounts/{accountId}/bills", method= RequestMethod.GET) + public ResponseEntity> getAllBillsForAccount(@PathVariable("accountId") Long accountId) { + return billService.getAllBillsForAccount(accountId); + } + + @RequestMapping(value="/bills/{billId}", method= RequestMethod.GET) + public ResponseEntity getBillById(@PathVariable("billId") Long billId) { + return billService.getBillById(billId); + } + + @RequestMapping(value="/customers/{customerId}/bills", method= RequestMethod.GET) + public ResponseEntity> getAllBillsForCustomer(@PathVariable Long customerId) { + return billService.getAllBillsForCustomer(); + } + + @RequestMapping(value="/accounts/{accountId}/bills", method = RequestMethod.POST) + public ResponseEntity createBill(@PathVariable Long accountId, @RequestBody Bill bill) { + return billService.createBill(bill); + } + + @RequestMapping(value = "/bills/{billId}", method = RequestMethod.PUT) + public ResponseEntity updateBill(@PathVariable Long billId, @RequestBody Bill bill) { + return billService.updateBill(bill); + } + + @RequestMapping(value = "/bills/{billId}", method = RequestMethod.DELETE) + public ResponseEntity deleteBill(@PathVariable Long billId) { + return billService.deleteBill(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..5e3ec62 --- /dev/null +++ b/src/main/java/io/zipcoder/controller/CustomerController.java @@ -0,0 +1,47 @@ +package io.zipcoder.controller; + + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import io.zipcoder.repository.CustomerRepository; +import io.zipcoder.service.AccountService; +import io.zipcoder.service.CustomerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +public class CustomerController { + + private CustomerService customerService; + + @Autowired + public CustomerController(CustomerService customerService){ + this.customerService = customerService; + } + + @RequestMapping(value = "/customers", method = RequestMethod.GET) + public ResponseEntity> getAllCustomers(){ + return customerService.getAllCustomers(); + } + + @RequestMapping(value = "/customers/{id}", method = RequestMethod.GET) + public ResponseEntity getCustomerById(@PathVariable("id") Long id){ + return customerService.getCustomerById(id); + } + + @RequestMapping(value = "/accounts/{accountId}/customer", method = RequestMethod.GET) + public ResponseEntity getCustomer(@PathVariable("accountId") Long accountId){ + return customerService.getCustomerOfAccount(accountId); + } + + @RequestMapping(value = "/customers", method = RequestMethod.POST) + public ResponseEntity createCustomer(@RequestBody Customer customer){ + return customerService.createCustomer(customer); + } + + @RequestMapping(value = "/customers/{id}", method = RequestMethod.PUT) + public ResponseEntity updateCustomer(@PathVariable("id") Long id, @RequestBody Customer customer){ + return customerService.updateCustomer(customer, id); + } +} 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..71166d9 --- /dev/null +++ b/src/main/java/io/zipcoder/domain/Account.java @@ -0,0 +1,76 @@ +package io.zipcoder.domain; + +import javax.persistence.*; + +@Entity +public class Account { + + @Id + @GeneratedValue + @Column(name ="ACCOUNT_ID") + private Long id; + + @Column(name = "ACCOUNT_TYPE") + private String type; + + @Column(name = "NICKNAME") + private String nickname; + + @Column(name = "REWARDS") + private Integer rewards; + + @Column(name="BALANCE") + private Double balance; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "CUSTOMER_ID") + private Customer customer; + + 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/AccountType.java b/src/main/java/io/zipcoder/domain/AccountType.java new file mode 100644 index 0000000..437bbfe --- /dev/null +++ b/src/main/java/io/zipcoder/domain/AccountType.java @@ -0,0 +1,10 @@ +package io.zipcoder.domain; + +public enum AccountType { +SAVINGS("savings"), CHECKING("checking"), CREDIT("credit"); + +private String type; +AccountType(String type){ + this.type = type; +} +} 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..547704c --- /dev/null +++ b/src/main/java/io/zipcoder/domain/Address.java @@ -0,0 +1,77 @@ +package io.zipcoder.domain; + + +import javax.persistence.*; + +@Entity +public class Address { + + @Id + @GeneratedValue + @Column(name = "ADDRESS_ID") + private Long id; + + @Column(name = "STREET_NUMBER") + private String street_number; + + @Column(name = "STREET_NAME") + private String street_name; + + @Column(name = "CITY") + private String city; + + @Column(name = "STATE") + private String state; + + @Column(name = "ZIP") + private String zip; + + + 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..e4856dc --- /dev/null +++ b/src/main/java/io/zipcoder/domain/Bill.java @@ -0,0 +1,134 @@ +package io.zipcoder.domain; + +import javax.persistence.*; + +@Entity +public class Bill { + + @Id + @GeneratedValue + @Column(name = "BILL_ID") + private Long id; + + @Column(name = "STATUS") + private String status; + + @Column(name = "PAYEE") + private String payee; + + @Column(name = "NICKNAME") + private String nickname; + + @Column(name = "CREATION_DATE") + private String creation_date; + + @Column(name = "PAYMENT_DATE") + private String payment_date; + + @Column(name = "RECURRING_DATE") + private Integer recurring_date; + + @Column(name = "UPCOMING_PAYMENT_DATE") + private String upcoming_payment_date; + + @Column(name = "PAYMENT_AMOUNT") + private Double payment_amount; + + @ManyToOne + @JoinColumn(name = "ACCOUNT_ID") +// private String 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 getNickname() { + return nickname; + } + + public void setNickname(String nickname) { + this.nickname = nickname; + } + + 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 String getAccount_id() { +// return account_id; +// } +// +// public void setAccount_id(String account_id) { +// this.account_id = account_id; +// } + + 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..dc0e5d8 --- /dev/null +++ b/src/main/java/io/zipcoder/domain/Customer.java @@ -0,0 +1,58 @@ +package io.zipcoder.domain; + +import javax.persistence.*; +import java.util.List; +import java.util.Set; + + +@Entity +public class Customer { + + @Id + @GeneratedValue + @Column(name = "CUSTOMER_ID") + private Long id; + + @Column(name = "FIRST_NAME") + private String first_name; + + @Column(name="LAST_NAME") + private String last_name; + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(name = "ADDRESS_ID") + private Set
addresses; + + + 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 Set
getAddress() { + return addresses; + } + + public void setAddress(Set
addresses) { + this.addresses = addresses; + } +} 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..7663599 --- /dev/null +++ b/src/main/java/io/zipcoder/repository/AccountRepository.java @@ -0,0 +1,10 @@ +package io.zipcoder.repository; + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface AccountRepository extends CrudRepository { +IterablefindAllByCustomer_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..8d0f16a --- /dev/null +++ b/src/main/java/io/zipcoder/repository/BillRepository.java @@ -0,0 +1,15 @@ +package io.zipcoder.repository; + +import io.zipcoder.domain.Bill; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BillRepository extends CrudRepository{ + + Iterable findAllByAccount_Id(Long accountId); + + Iterable findAllByAccount_Customer_Id(Long customerId); + + Iterable findById(Long billId); +} 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..c0ea981 --- /dev/null +++ b/src/main/java/io/zipcoder/repository/CustomerRepository.java @@ -0,0 +1,10 @@ +package io.zipcoder.repository; + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface CustomerRepository extends CrudRepository { + +} diff --git a/src/main/java/io/zipcoder/service/AccountService.java b/src/main/java/io/zipcoder/service/AccountService.java new file mode 100644 index 0000000..070bed7 --- /dev/null +++ b/src/main/java/io/zipcoder/service/AccountService.java @@ -0,0 +1,61 @@ +package io.zipcoder.service; + + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import io.zipcoder.repository.AccountRepository; +import io.zipcoder.repository.CustomerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.net.URI; + +@Service +public class AccountService { + + private AccountRepository accountRepository; + private CustomerRepository customerRepository; + + @Autowired + public AccountService(AccountRepository accountRepository, CustomerRepository customerRepository){ + this.accountRepository = accountRepository; + this.customerRepository = customerRepository; + } + + public ResponseEntity getAllAccounts(){ + Iterable accounts = accountRepository.findAll(); + return new ResponseEntity<>(accounts, HttpStatus.OK); + } + + public ResponseEntity getAccountById(Long id){ + Account account = accountRepository.findOne(id); + return new ResponseEntity<>(account, HttpStatus.OK); + } + + public ResponseEntity getAccountsOfCustomer(Long customerId){ + Iterable accounts = accountRepository.findAllByCustomer_Id(customerId); + return new ResponseEntity<>(accounts, HttpStatus.OK); + } + + public ResponseEntity createAccount(Long customerId, Account account){ + Customer customer = customerRepository.findOne(customerId); + account.setCustomer(customer); + Account account1 = accountRepository.save(account); + return new ResponseEntity<>(account1, HttpStatus.CREATED); + } + + public ResponseEntity updateAccount(Account account, Long accountId){ + account.setId(accountId); + Account account1 = accountRepository.save(account); + return new ResponseEntity<>(account1, HttpStatus.OK); + } + + public ResponseEntity deleteAccount(Long accountId){ + accountRepository.delete(accountId); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/src/main/java/io/zipcoder/service/BillService.java b/src/main/java/io/zipcoder/service/BillService.java new file mode 100644 index 0000000..628f014 --- /dev/null +++ b/src/main/java/io/zipcoder/service/BillService.java @@ -0,0 +1,70 @@ +package io.zipcoder.service; + +import io.zipcoder.domain.Bill; +import io.zipcoder.repository.AccountRepository; +import io.zipcoder.repository.BillRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.net.URI; + +@Service +public class BillService { + + @Autowired + private BillRepository billRepository; + private AccountRepository accountRepository; + + public BillService() {} + + public BillService(BillRepository billRepository, AccountRepository accountRepository) { + this.billRepository = billRepository; + this.accountRepository = accountRepository; + } + + public ResponseEntity> getAllBillsForAccount(Long accountId) { + Iterable allBillsForAccount = billRepository.findAllByAccount_Id(accountId); + return new ResponseEntity<>(allBillsForAccount, HttpStatus.OK); + } + + public ResponseEntity getBillById(Long billId) { + /* + Account account = accountRepo.findById(accountId).orElse(new Account()); + return new ResponseEntity<>(account, OK); + */ + // need to rework this. +// Bill bill = billRepository.findById(billId); +// return new ResponseEntity<>(bill, HttpStatus.OK); + } + + public ResponseEntity> getAllBillsForCustomer() { + Iterable allBillsForCustomer = billRepository.findAll(); + return new ResponseEntity<>(allBillsForCustomer, HttpStatus.OK); + } + + public ResponseEntity createBill(Bill bill) { + bill = billRepository.save(bill); + URI newBillUri = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(bill.getId()) + .toUri(); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.setLocation(newBillUri); + return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED); + } + + public ResponseEntity updateBill(Bill bill) { + Bill bill1 = billRepository.save(bill); + return new ResponseEntity<>(HttpStatus.OK); + } + + public ResponseEntity deleteBill(Long billId) { + billRepository.delete(billId); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/src/main/java/io/zipcoder/service/CustomerService.java b/src/main/java/io/zipcoder/service/CustomerService.java new file mode 100644 index 0000000..0b1b810 --- /dev/null +++ b/src/main/java/io/zipcoder/service/CustomerService.java @@ -0,0 +1,65 @@ +package io.zipcoder.service; + + +import io.zipcoder.domain.Account; +import io.zipcoder.domain.Customer; +import io.zipcoder.repository.AccountRepository; +import io.zipcoder.repository.CustomerRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.net.URI; + +@Service +public class CustomerService { + + private CustomerRepository customerRepository; + private AccountRepository accountRepository; + + public CustomerService(){} + + @Autowired + public CustomerService(CustomerRepository customerRepository, AccountRepository accountRepository){ + this.customerRepository = customerRepository; + this.accountRepository = accountRepository; + } + + public ResponseEntity> getAllCustomers(){ + Iterable accounts = customerRepository.findAll(); + return new ResponseEntity<>(accounts, HttpStatus.OK); + } + + public ResponseEntity getCustomerById(Long id){ + Customer customer = customerRepository.findOne(id); + return new ResponseEntity<>(customer, HttpStatus.OK); + } + + public ResponseEntity getCustomerOfAccount(Long accountId){ + Account account = accountRepository.findOne(accountId); + Customer customer = account.getCustomer(); + return new ResponseEntity<>(customer, HttpStatus.OK); + } + + public ResponseEntity createCustomer(Customer customer){ + Customer customer1 = customerRepository.save(customer); + URI newAccountUri = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(customer.getId()) + .toUri(); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.setLocation(newAccountUri); + return new ResponseEntity<>(customer1, responseHeaders, HttpStatus.CREATED); + } + + public ResponseEntity updateCustomer(Customer customer, Long customerId){ + customer.setId(customerId); + Customer customer1 = customerRepository.save(customer); + return new ResponseEntity<>(customer1, HttpStatus.OK); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..23a6c49 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#spring.jpa.hibernate.ddl-auto=create +#spring.datasource.url=jdbc:mysql://localhost:3306/bank_project +#spring.datasource.username=ourgroup +#spring.datasource.password=ThePassword diff --git a/src/test/java/io/zipcoder/ZcwbankApplicationTests.java b/src/test/java/io/zipcoder/ZcwbankApplicationTests.java index 846d527..26aac95 100644 --- a/src/test/java/io/zipcoder/ZcwbankApplicationTests.java +++ b/src/test/java/io/zipcoder/ZcwbankApplicationTests.java @@ -1,5 +1,6 @@ package io.zipcoder; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/io/zipcoder/controllerTest/AccountControllerTest.java b/src/test/java/io/zipcoder/controllerTest/AccountControllerTest.java new file mode 100644 index 0000000..b0523b5 --- /dev/null +++ b/src/test/java/io/zipcoder/controllerTest/AccountControllerTest.java @@ -0,0 +1,42 @@ +package io.zipcoder.controllerTest; + +import io.zipcoder.controller.AccountController; + +import io.zipcoder.service.AccountService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.*; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +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.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.internal.verification.VerificationModeFactory.times; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(AccountController.class) +public class AccountControllerTest { + + @Autowired + private MockMvc mvc; + + @MockBean + private AccountService accountService; + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + } + +} diff --git a/src/test/java/io/zipcoder/controllerTest/CustomerControllerTest.java b/src/test/java/io/zipcoder/controllerTest/CustomerControllerTest.java new file mode 100644 index 0000000..4708538 --- /dev/null +++ b/src/test/java/io/zipcoder/controllerTest/CustomerControllerTest.java @@ -0,0 +1,66 @@ +package io.zipcoder.controllerTest; + +import io.zipcoder.controller.CustomerController; + +import io.zipcoder.service.CustomerService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.*; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +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.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.internal.verification.VerificationModeFactory.times; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(CustomerController.class) +public class CustomerControllerTest { + + @Autowired + private MockMvc mvc; + + @MockBean + private CustomerService customerService; + + @Before + public void setup(){ + + } + + @Test + public void testGetAllCustomers(){ + + } + + @Test + public void testGetCustomerById(){ + + } + + @Test + public void testGetCustomer(){ + + } + + @Test + public void testCreateCustomer(){ + + } + + @Test + public void testUpdateCustomer(){ + + } +} diff --git a/src/test/java/io/zipcoder/domainTest/AccountTest.java b/src/test/java/io/zipcoder/domainTest/AccountTest.java new file mode 100644 index 0000000..6812bbb --- /dev/null +++ b/src/test/java/io/zipcoder/domainTest/AccountTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.domainTest; + +public class AccountTest { +} diff --git a/src/test/java/io/zipcoder/domainTest/AddressTest.java b/src/test/java/io/zipcoder/domainTest/AddressTest.java new file mode 100644 index 0000000..41a7dea --- /dev/null +++ b/src/test/java/io/zipcoder/domainTest/AddressTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.domainTest; + +public class AddressTest { +} diff --git a/src/test/java/io/zipcoder/domainTest/BillTest.java b/src/test/java/io/zipcoder/domainTest/BillTest.java new file mode 100644 index 0000000..3964406 --- /dev/null +++ b/src/test/java/io/zipcoder/domainTest/BillTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.domainTest; + +public class BillTest { +} diff --git a/src/test/java/io/zipcoder/domainTest/CustomerTest.java b/src/test/java/io/zipcoder/domainTest/CustomerTest.java new file mode 100644 index 0000000..b8f7320 --- /dev/null +++ b/src/test/java/io/zipcoder/domainTest/CustomerTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.domainTest; + +public class CustomerTest { +} diff --git a/src/test/java/io/zipcoder/repositoryTest/AccountRepositoryTest.java b/src/test/java/io/zipcoder/repositoryTest/AccountRepositoryTest.java new file mode 100644 index 0000000..f4f2775 --- /dev/null +++ b/src/test/java/io/zipcoder/repositoryTest/AccountRepositoryTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.repositoryTest; + +public class AccountRepositoryTest { +} diff --git a/src/test/java/io/zipcoder/repositoryTest/CustomerRepositoryTest.java b/src/test/java/io/zipcoder/repositoryTest/CustomerRepositoryTest.java new file mode 100644 index 0000000..871a7c7 --- /dev/null +++ b/src/test/java/io/zipcoder/repositoryTest/CustomerRepositoryTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.repositoryTest; + +public class CustomerRepositoryTest { +} diff --git a/src/test/java/io/zipcoder/serviceTest/AccountServiceTest.java b/src/test/java/io/zipcoder/serviceTest/AccountServiceTest.java new file mode 100644 index 0000000..4113fa6 --- /dev/null +++ b/src/test/java/io/zipcoder/serviceTest/AccountServiceTest.java @@ -0,0 +1,33 @@ +package io.zipcoder.serviceTest; + +import io.zipcoder.repository.AccountRepository; +import io.zipcoder.service.AccountService; +import io.zipcoder.domain.Account; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.mockito.Mockito.*; +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.is; + +public class AccountServiceTest { + @Mock + private AccountRepository mockRepo; + + @InjectMocks + private AccountService mockService; + + @Before + public void setUp() throws Exception{ + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGetAllAccounts(){ + + } +} diff --git a/src/test/java/io/zipcoder/serviceTest/CustomerServiceTest.java b/src/test/java/io/zipcoder/serviceTest/CustomerServiceTest.java new file mode 100644 index 0000000..5ffef39 --- /dev/null +++ b/src/test/java/io/zipcoder/serviceTest/CustomerServiceTest.java @@ -0,0 +1,56 @@ +package io.zipcoder.serviceTest; + + +import io.zipcoder.domain.Customer; +import io.zipcoder.repository.CustomerRepository; +import io.zipcoder.service.CustomerService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.mockito.Mockito.*; +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.is; + + +public class CustomerServiceTest { + @Mock + private CustomerRepository mockRepo; + + @InjectMocks + private CustomerService mockService; + + @Before + public void setUp() throws Exception{ + MockitoAnnotations.initMocks(this); + } + + @Test + public void testCreateCustomer(){ + + } + + @Test + public void testGetAllCustomers(){ + + } + + @Test + public void testGetCustomerById(){ + + } + + @Test + public void testUpdateCustomer(){ + + } + + @Test + public void testGetCustomerOfAccount(){ + + } + +}