-
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
051fcc6
commit 9ccf256
Showing
22 changed files
with
560 additions
and
40 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
bank-common/src/main/java/org/siriusxi/blueharvest/bank/common/api/dto/TransactionDTO.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,12 +1,18 @@ | ||
package org.siriusxi.blueharvest.bank.common.api.dto; | ||
|
||
import lombok.Data; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Data | ||
@RequiredArgsConstructor | ||
public class TransactionDTO { | ||
|
||
@NonNull | ||
private int accountId; | ||
|
||
@NonNull | ||
private BigDecimal amount; | ||
} |
23 changes: 23 additions & 0 deletions
23
bank-common/src/main/java/org/siriusxi/blueharvest/bank/util/JsonUtilities.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,23 @@ | ||
package org.siriusxi.blueharvest.bank.util; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
|
||
public final class JsonUtilities { | ||
|
||
private JsonUtilities(){} | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
public static String toJson(Object object) throws IOException { | ||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
return mapper.writeValueAsString(object); | ||
} | ||
|
||
public static byte[] toJsonAsByte(Object object) throws IOException { | ||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
return mapper.writeValueAsBytes(object); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...t-service/src/main/java/org/siriusxi/blueharvest/bank/as/config/ServiceConfiguration.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,14 @@ | ||
package org.siriusxi.blueharvest.bank.as.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class ServiceConfiguration { | ||
|
||
@Bean | ||
RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
45 changes: 42 additions & 3 deletions
45
...ce/src/main/java/org/siriusxi/blueharvest/bank/as/integration/TransactionIntegration.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,19 +1,58 @@ | ||
package org.siriusxi.blueharvest.bank.as.integration; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.siriusxi.blueharvest.bank.common.api.composite.trx.Transaction; | ||
import org.siriusxi.blueharvest.bank.common.api.dto.TransactionDTO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
import static org.springframework.http.HttpMethod.GET; | ||
|
||
@Component | ||
@Log4j2 | ||
public class TransactionIntegration { | ||
|
||
public List<Transaction> getAccountTransactions(int id){ | ||
return List.of(); | ||
private final RestTemplate restTemplate; | ||
|
||
private final String transactionServiceUrl; | ||
|
||
private final String BASE_URL = "/bank/api/v1/"; | ||
|
||
private final String QUERY_PARAM = "?accountId="; | ||
|
||
@Autowired | ||
public TransactionIntegration( | ||
RestTemplate restTemplate, | ||
@Value("${app.transaction-service.host}") String transactionServiceHost, | ||
@Value("${app.transaction-service.port}") int transactionServicePort) { | ||
|
||
this.restTemplate = restTemplate; | ||
|
||
transactionServiceUrl = "http://" | ||
.concat(transactionServiceHost) | ||
.concat(":") | ||
.concat(String.valueOf(transactionServicePort)) | ||
.concat(BASE_URL) | ||
.concat("transactions"); | ||
} | ||
|
||
public void createTransaction(TransactionDTO transaction) { | ||
public List<Transaction> getAccountTransactions(int accountId){ | ||
|
||
String url = transactionServiceUrl.concat(QUERY_PARAM).concat(String.valueOf(accountId)); | ||
log.debug("Will call getCustomerAccounts API on URL: {}", url); | ||
|
||
return restTemplate.exchange(url, GET, null, | ||
new ParameterizedTypeReference<List<Transaction>>() {}).getBody(); | ||
} | ||
|
||
public void createTransaction(TransactionDTO transaction) { | ||
restTemplate.postForObject(transactionServiceUrl,transaction, TransactionDTO.class); | ||
} | ||
|
||
|
||
} |
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
37 changes: 37 additions & 0 deletions
37
...ice/src/test/java/org/siriusxi/blueharvest/bank/as/AccountRepositoryIntegrationTests.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,37 @@ | ||
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.siriusxi.blueharvest.bank.common.api.composite.trx.TransactionType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataJpaTest | ||
class AccountRepositoryIntegrationTests { | ||
|
||
@Autowired | ||
private AccountRepository accountRepository; | ||
|
||
@Test | ||
void whenFindByCustomerId_thenReturnAccount() { | ||
// given | ||
AccountEntity trx = new AccountEntity(99, new BigDecimal("100.20")); | ||
accountRepository.save(trx); | ||
|
||
// when | ||
AccountEntity found = | ||
accountRepository.findByCustomerId(trx.getCustomerId()).iterator().next(); | ||
|
||
// then | ||
assertThat(found.getId()).isEqualTo(1); | ||
assertThat(found.getCustomerId()).isEqualTo(99); | ||
assertThat(found.getBalance()).isEqualTo(new BigDecimal("100.20")); | ||
assertThat(found.getType()).isEqualTo(AccountType.CURRENT); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...r-service/src/main/java/org/siriusxi/blueharvest/bank/cs/config/ServiceConfiguration.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,14 @@ | ||
package org.siriusxi.blueharvest.bank.cs.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class ServiceConfiguration { | ||
|
||
@Bean | ||
RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
44 changes: 42 additions & 2 deletions
44
...ervice/src/main/java/org/siriusxi/blueharvest/bank/cs/integration/AccountIntegration.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,16 +1,56 @@ | ||
package org.siriusxi.blueharvest.bank.cs.integration; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.siriusxi.blueharvest.bank.common.api.composite.account.Account; | ||
import org.siriusxi.blueharvest.bank.common.api.dto.AccountDTO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
import static org.springframework.http.HttpMethod.GET; | ||
|
||
@Component | ||
@Log4j2 | ||
public class AccountIntegration { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
private final String accountServiceUrl; | ||
|
||
private final String BASE_URL = "/bank/api/v1/"; | ||
|
||
private final String QUERY_PARAM = "?customerId="; | ||
|
||
@Autowired | ||
public AccountIntegration( | ||
RestTemplate restTemplate, | ||
@Value("${app.account-service.host}") String accountServiceHost, | ||
@Value("${app.account-service.port}") int accountServicePort) { | ||
|
||
this.restTemplate = restTemplate; | ||
|
||
public List<Account> getCustomerAccounts(int id){ | ||
return List.of(); | ||
accountServiceUrl = "http://" | ||
.concat(accountServiceHost) | ||
.concat(":") | ||
.concat(String.valueOf(accountServicePort)) | ||
.concat(BASE_URL) | ||
.concat("accounts"); | ||
} | ||
|
||
public List<Account> getCustomerAccounts(int customerId){ | ||
|
||
String url = accountServiceUrl.concat(QUERY_PARAM).concat(String.valueOf(customerId)); | ||
log.debug("Will call getCustomerAccounts API on URL: {}", url); | ||
|
||
return restTemplate.exchange(url, GET, null, | ||
new ParameterizedTypeReference<List<Account>>() {}).getBody(); | ||
} | ||
|
||
public void createAccount(AccountDTO account) { | ||
restTemplate.postForObject(accountServiceUrl,account, AccountDTO.class); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...ce/src/test/java/org/siriusxi/blueharvest/bank/cs/CustomerRepositoryIntegrationTests.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,59 @@ | ||
package org.siriusxi.blueharvest.bank.cs; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.siriusxi.blueharvest.bank.cs.persistence.CustomerRepository; | ||
import org.siriusxi.blueharvest.bank.cs.persistence.entity.CustomerEntity; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DataJpaTest | ||
class CustomerRepositoryIntegrationTests { | ||
|
||
@Autowired | ||
private CustomerRepository customerRepository; | ||
|
||
@Test | ||
void whenFindAllCustomers_thenReturn7Customers() { | ||
// given all 7 employees already initialized | ||
|
||
// when | ||
Iterable<CustomerEntity> found = customerRepository.findAll(); | ||
|
||
// then | ||
assertThat(found.spliterator().getExactSizeIfKnown()).isEqualTo(7); | ||
} | ||
|
||
@Test | ||
void updateCustomerBalance() { | ||
// given 7th employee already initialized with balance 0.0 | ||
Optional<CustomerEntity> foundCustomer = customerRepository.findById(7); | ||
|
||
CustomerEntity customer = null; | ||
|
||
if (foundCustomer.isPresent()) | ||
customer = foundCustomer.get(); | ||
|
||
assertThat(customer.getBalance()).isEqualTo(new BigDecimal("0.00")); | ||
|
||
// when | ||
customer.setBalance(new BigDecimal("9999.90")); | ||
customerRepository.save(customer); | ||
|
||
// then | ||
foundCustomer = null; | ||
customer = null; | ||
|
||
foundCustomer = customerRepository.findById(7); | ||
|
||
if (foundCustomer.isPresent()) | ||
customer = foundCustomer.get(); | ||
|
||
assertThat(customer.getBalance()).isEqualTo(new BigDecimal("9999.90")); | ||
} | ||
|
||
} |
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
Oops, something went wrong.