-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5ba5815
commit d1b2e35
Showing
21 changed files
with
833 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
bank-common/src/main/java/org/siriusxi/blueharvest/bank/common/api/dto/AccountDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package org.siriusxi.blueharvest.bank.common.api.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
public class AccountDTO { | ||
|
||
private int customerId; | ||
@NonNull | ||
private BigDecimal initialCredit; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...n/src/main/java/org/siriusxi/blueharvest/bank/common/exception/InvalidInputException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.siriusxi.blueharvest.bank.common.exception; | ||
|
||
public class InvalidInputException extends RuntimeException { | ||
|
||
public InvalidInputException() {} | ||
|
||
public InvalidInputException(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidInputException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public InvalidInputException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ommon/src/main/java/org/siriusxi/blueharvest/bank/common/exception/NotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.siriusxi.blueharvest.bank.common.exception; | ||
|
||
public class NotFoundException extends RuntimeException { | ||
|
||
public NotFoundException() {} | ||
|
||
public NotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public NotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public NotFoundException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...t-service/src/test/java/org/siriusxi/blueharvest/bank/as/AccountControllerLayerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.siriusxi.blueharvest.bank.as; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.siriusxi.blueharvest.bank.as.api.AccountController; | ||
import org.siriusxi.blueharvest.bank.as.service.AccountService; | ||
import org.siriusxi.blueharvest.bank.common.api.composite.account.Account; | ||
import org.siriusxi.blueharvest.bank.common.api.composite.trx.Transaction; | ||
import org.siriusxi.blueharvest.bank.common.api.dto.AccountDTO; | ||
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.test.web.servlet.MockMvc; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.siriusxi.blueharvest.bank.common.api.composite.account.AccountType.CURRENT; | ||
import static org.siriusxi.blueharvest.bank.common.api.composite.trx.TransactionType.CREDIT; | ||
import static org.siriusxi.blueharvest.bank.util.JsonUtilities.toJson; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(AccountController.class) | ||
class AccountControllerLayerTests { | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@MockBean | ||
private AccountService accountService; | ||
|
||
@BeforeEach | ||
void setup() { | ||
// Given | ||
given(accountService.getAccounts(1)) | ||
.willReturn( | ||
List.of( | ||
new Account( | ||
1, | ||
new BigDecimal("1.0"), | ||
CURRENT, | ||
List.of(new Transaction(1, CREDIT, new BigDecimal("1.0")))))); | ||
} | ||
|
||
@Test | ||
void whenInitialCreditGreaterThanZero_thenCreateAccountAndTransaction() throws Exception { | ||
|
||
// When | ||
mvc.perform( | ||
post("/bank/api/v1/accounts") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(toJson(new AccountDTO(1, new BigDecimal("1.0"))))) | ||
.andExpect(status().isOk()); | ||
|
||
var accounts = accountService.getAccounts(1); | ||
|
||
// Then | ||
assertThat(accounts.get(0).balance()).isEqualTo(new BigDecimal("1.0")); | ||
|
||
assertThat(accounts.get(0).type()).isEqualTo(CURRENT); | ||
|
||
assertThat(accounts.get(0).transactions()).isNotNull(); | ||
assertThat(accounts.get(0).transactions().size()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
void getAccountsByCustomerId_thenReturnAccountsAndTransactionsJsonArray() throws Exception { | ||
|
||
// When | ||
mvc.perform(get("/bank/api/v1/accounts?customerId=1") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
// Then | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$", hasSize(1))) | ||
.andExpect(jsonPath("$[0].balance", is(1.0))) | ||
.andExpect(jsonPath("$[0].customerId", is(1))) | ||
.andExpect(jsonPath("$[0].type", is("CURRENT"))) | ||
.andExpect(jsonPath("$[0].transactions", hasSize(1))) | ||
.andExpect(jsonPath("$[0].transactions[0].accountId", is(1))) | ||
.andExpect(jsonPath("$[0].transactions[0].type", is("CREDIT"))) | ||
.andExpect(jsonPath("$[0].transactions[0].amount", is(1.0))); | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
...ice/src/test/java/org/siriusxi/blueharvest/bank/as/AccountRepositoryIntegrationTests.java
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...t-service/src/test/java/org/siriusxi/blueharvest/bank/as/AccountRepositoryLayerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.siriusxi.blueharvest.bank.as; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.siriusxi.blueharvest.bank.as.persistence.AccountRepository; | ||
import org.siriusxi.blueharvest.bank.as.persistence.entity.AccountEntity; | ||
import org.siriusxi.blueharvest.bank.common.api.composite.account.AccountType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataJpaTest | ||
class AccountRepositoryLayerTests { | ||
|
||
@Autowired | ||
private AccountRepository accountRepository; | ||
|
||
@Test | ||
void whenFindByCustomerId_thenReturnAccounts() { | ||
// given | ||
accountRepository.saveAll(List.of( | ||
new AccountEntity(99, new BigDecimal("100.20")), | ||
new AccountEntity(99, new BigDecimal("200.20")))); | ||
|
||
// when | ||
var accounts = accountRepository.findByCustomerId(99); | ||
|
||
var account = accounts.get(0); | ||
|
||
// then | ||
assertThat(accounts.size()).isEqualTo(2); | ||
|
||
assertThat(account.getId()).isEqualTo(1); | ||
assertThat(account.getCustomerId()).isEqualTo(99); | ||
assertThat(account.getBalance()).isEqualTo(new BigDecimal("100.20")); | ||
assertThat(account.getType()).isEqualTo(AccountType.CURRENT); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
...ervice/src/test/java/org/siriusxi/blueharvest/bank/as/AccountServiceApplicationTests.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.