From bdcdae862d7bb846fee967e19a099cdf084e7edc Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 01:09:39 +0300 Subject: [PATCH 1/6] -added tests for new endpoints --- .../accounts/AccountTransactionInfo.java | 16 +++++++ .../examples/bank/web/EndToEndTest.java | 47 ++++++++++++++++++ .../web/BankingWebIntegrationTest.java | 48 ++++++++++++++++++- 3 files changed, 110 insertions(+), 1 deletion(-) diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java index bdc0c01..c617635 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java @@ -1,5 +1,8 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + public class AccountTransactionInfo { private String transactionId; @@ -7,6 +10,9 @@ public class AccountTransactionInfo { private String toAccountId; private long amount; + public AccountTransactionInfo() { + } + public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount) { this.transactionId = transactionId; this.fromAccountId = fromAccountId; @@ -45,4 +51,14 @@ public class AccountTransactionInfo { public void setAmount(long amount) { this.amount = amount; } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java index 1f22c81..d21e936 100644 --- a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java +++ b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.examples.bank.web; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountTransactionInfo; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils; @@ -15,6 +16,8 @@ import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; import net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils; import org.junit.Assert; import org.junit.Test; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -22,9 +25,11 @@ import org.springframework.web.client.RestTemplate; import rx.Observable; import java.math.BigDecimal; +import java.util.List; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo; +import static org.junit.Assert.assertTrue; public class EndToEndTest { @@ -122,6 +127,48 @@ public class EndToEndTest { assertAccountBalance(toAccountId, finalToAccountBalance); // TOOD - check state of money transfer + + List transactionInfoList = restTemplate.exchange(accountsQuerySideBaseUrl("/accounts/"+fromAccountId+"/history"), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody(); + + AccountTransactionInfo expectedTransactionInfo = new AccountTransactionInfo(moneyTransfer.getMoneyTransferId(), fromAccountId, toAccountId, toCents(amountToTransfer).longValue()); + + assertTrue(transactionInfoList.contains(expectedTransactionInfo)); + } + + @Test + public void shouldCreateAccountsAndGetByCustomer() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + CustomerInfo customerInfo = generateCustomerInfo(); + + final CustomerResponse customerResponse = restTemplate.postForEntity(customersCommandSideBaseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); + + Assert.assertNotNull(customerId); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + + customersTestUtils.assertCustomerResponse(customerId, customerInfo); + + final CreateAccountResponse account = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + accountsCommandSideBaseUrl("/accounts"), + HttpMethod.POST, + CreateAccountResponse.class, + new CreateAccountRequest(customerId, "My 1 Account", "", initialFromAccountBalance) + ); + final String accountId = account.getAccountId(); + + Assert.assertNotNull(accountId); + + assertAccountBalance(accountId, initialFromAccountBalance); + + List accountResponseList = restTemplate.exchange(accountsQuerySideBaseUrl("/accounts?customerId="+customerId), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody(); + + assertTrue(accountResponseList.stream().filter(acc -> acc.getAccountId().equals(accountId)).findFirst().isPresent()); } private BigDecimal toCents(BigDecimal dollarAmount) { diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java index 70352bc..a3276f9 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java @@ -1,5 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountTransactionInfo; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountRequest; @@ -17,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @@ -25,10 +28,12 @@ import rx.Observable; import javax.annotation.PostConstruct; import java.math.BigDecimal; +import java.util.List; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateToAccountInfo; +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class) @@ -97,6 +102,47 @@ public class BankingWebIntegrationTest { assertAccountBalance(fromAccountId, finalFromAccountBalance); assertAccountBalance(toAccountId, finalToAccountBalance); + List transactionInfoList = restTemplate.exchange(baseUrl("/accounts/"+fromAccountId+"/history"), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody(); + + AccountTransactionInfo expectedTransactionInfo = new AccountTransactionInfo(moneyTransfer.getMoneyTransferId(), fromAccountId, toAccountId, toCents(amountToTransfer).longValue()); + + assertTrue(transactionInfoList.contains(expectedTransactionInfo)); + } + + @Test + public void shouldCreateAccountsAndGetByCustomer() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + CustomerInfo customerInfo = generateCustomerInfo(); + + final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); + + Assert.assertNotNull(customerId); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + + customersTestUtils.assertCustomerResponse(customerId, customerInfo); + + final CreateAccountResponse account = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + baseUrl("/accounts"), + HttpMethod.POST, + CreateAccountResponse.class, + new CreateAccountRequest(customerId, "My 1 Account", "", initialFromAccountBalance) + ); + final String accountId = account.getAccountId(); + + Assert.assertNotNull(accountId); + + assertAccountBalance(accountId, initialFromAccountBalance); + + List accountResponseList = restTemplate.exchange(baseUrl("/accounts?customerId="+customerId), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody(); + + assertTrue(accountResponseList.stream().filter(acc -> acc.getAccountId().equals(accountId)).findFirst().isPresent()); } @Test @@ -163,7 +209,7 @@ public class BankingWebIntegrationTest { @Override public void verify(QuerySideCustomer customerResponse) { Assert.assertEquals(customerId, customerResponse.getId()); - Assert.assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); + assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); } }); } From 7c6328aa5e6420d492529b89e4e2f61ce5bd55de Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 14:46:03 +0300 Subject: [PATCH 2/6] added new fields to TransferDetails --- .../common/transactions/TransferDetails.java | 17 +++++++++++++++++ .../examples/bank/web/EndToEndTest.java | 2 +- .../banking/web/BankingWebIntegrationTest.java | 2 +- .../CreateMoneyTransferRequest.java | 13 ++++++++++++- .../transactions/MoneyTransferController.java | 6 +++++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/transactions/TransferDetails.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/transactions/TransferDetails.java index 4567cf8..0425c76 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/transactions/TransferDetails.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/transactions/TransferDetails.java @@ -7,20 +7,29 @@ case class TransferDetails(fromAccountId : EntityIdentifier, toAccountId : Entit import net.chrisrichardson.eventstore.EntityIdentifier; import java.math.BigDecimal; +import java.util.Date; public class TransferDetails { private EntityIdentifier fromAccountId; private EntityIdentifier toAccountId; private BigDecimal amount; + private Date date; + private String description; private TransferDetails() { } public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount) { + this(fromAccountId, toAccountId, amount, new Date(), ""); + } + + public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount, Date date, String description) { this.fromAccountId = fromAccountId; this.toAccountId = toAccountId; this.amount = amount; + this.date = date; + this.description = description; } public EntityIdentifier getFromAccountId() { @@ -34,4 +43,12 @@ public class TransferDetails { public BigDecimal getAmount() { return amount; } + + public Date getDate() { + return date; + } + + public String getDescription() { + return description; + } } diff --git a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java index d21e936..42ae305 100644 --- a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java +++ b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java @@ -120,7 +120,7 @@ public class EndToEndTest { transactionsCommandSideBaseUrl("/transfers"), HttpMethod.POST, CreateMoneyTransferResponse.class, - new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer) + new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, "") ); assertAccountBalance(fromAccountId, finalFromAccountBalance); diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java index a3276f9..76439e0 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java @@ -96,7 +96,7 @@ public class BankingWebIntegrationTest { baseUrl("/transfers"), HttpMethod.POST, CreateMoneyTransferResponse.class, - new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer) + new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, "") ); assertAccountBalance(fromAccountId, finalFromAccountBalance); diff --git a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java index a043540..d3c07a6 100644 --- a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java +++ b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java @@ -15,13 +15,16 @@ public class CreateMoneyTransferRequest { @DecimalMin("0.01") private BigDecimal amount; + private String description; + public CreateMoneyTransferRequest() { } - public CreateMoneyTransferRequest(String fromAccountId, String toAccountId, BigDecimal amount) { + public CreateMoneyTransferRequest(String fromAccountId, String toAccountId, BigDecimal amount, String description) { this.fromAccountId = fromAccountId; this.toAccountId = toAccountId; this.amount = amount; + this.description = description; } public void setFromAccountId(String fromAccountId) { @@ -36,6 +39,10 @@ public class CreateMoneyTransferRequest { this.amount = amount; } + public void setDescription(String description) { + this.description = description; + } + public String getFromAccountId() { return fromAccountId; } @@ -47,4 +54,8 @@ public class CreateMoneyTransferRequest { public BigDecimal getAmount() { return amount; } + + public String getDescription() { + return description; + } } diff --git a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java index 749fe33..f2a6176 100644 --- a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java +++ b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java @@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import rx.Observable; +import java.util.Date; + @RestController @RequestMapping("/transfers") public class MoneyTransferController { @@ -27,7 +29,9 @@ public class MoneyTransferController { TransferDetails transferDetails = new TransferDetails( new EntityIdentifier(request.getFromAccountId()), new EntityIdentifier(request.getToAccountId()), - request.getAmount()); + request.getAmount(), + new Date(), + request.getDescription()); return moneyTransferService.transferMoney(transferDetails) .map(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdentifier().getId())); } From 7b54b9042d4f026f7310f824af762416708da48f Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 14:50:35 +0300 Subject: [PATCH 3/6] added new fields to TransferDetails --- .../accounts/AccountQueryWorkflow.java | 7 ++++- .../accounts/AccountTransactionInfo.java | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryWorkflow.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryWorkflow.java index 1f7842c..3b7e733 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryWorkflow.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryWorkflow.java @@ -53,7 +53,12 @@ public class AccountQueryWorkflow implements CompoundEventHandler { logger.info("**************** account version=" + fromAccountId + ", " + de.eventId().asString()); logger.info("**************** account version=" + toAccountId + ", " + de.eventId().asString()); - AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, fromAccountId, toAccountId, toIntegerRepr(de.event().getDetails().getAmount())); + AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, + fromAccountId, + toAccountId, + toIntegerRepr(de.event().getDetails().getAmount()), + de.event().getDetails().getDate(), + de.event().getDetails().getDescription()); accountInfoUpdateService.addTransaction(eventId, fromAccountId, ti); diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java index c617635..6a0f9a8 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java @@ -3,21 +3,31 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; +import java.util.Date; + public class AccountTransactionInfo { private String transactionId; private String fromAccountId; private String toAccountId; private long amount; + private Date date; + private String description; public AccountTransactionInfo() { } public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount) { + this(transactionId, fromAccountId, toAccountId, amount, new Date(), ""); + } + + public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount, Date date, String description) { this.transactionId = transactionId; this.fromAccountId = fromAccountId; this.toAccountId = toAccountId; this.amount = amount; + this.date = date; + this.description = description; } public String getTransactionId() { @@ -52,6 +62,22 @@ public class AccountTransactionInfo { this.amount = amount; } + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + @Override public boolean equals(Object o) { return EqualsBuilder.reflectionEquals(this, o); From 05ebfd7d146903241ebb4c414ef9c2b97836fdb6 Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 15:07:12 +0300 Subject: [PATCH 4/6] fixed tests --- .../javaexamples/banking/web/BankingWebIntegrationTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java index 76439e0..e4ce890 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java @@ -107,9 +107,11 @@ public class BankingWebIntegrationTest { new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), new ParameterizedTypeReference>() {}).getBody(); - AccountTransactionInfo expectedTransactionInfo = new AccountTransactionInfo(moneyTransfer.getMoneyTransferId(), fromAccountId, toAccountId, toCents(amountToTransfer).longValue()); - assertTrue(transactionInfoList.contains(expectedTransactionInfo)); + assertTrue(transactionInfoList.stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId()) && + ti.getFromAccountId().equals(fromAccountId) && + ti.getToAccountId().equals(toAccountId) && + ti.getAmount() == toCents(amountToTransfer).longValue()).findFirst().isPresent()); } @Test From 23fba9e462f0722254fb51c65056fae5169cc2b1 Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 15:07:48 +0300 Subject: [PATCH 5/6] fixed tests --- .../eventstore/examples/bank/web/EndToEndTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java index 42ae305..4f0d65a 100644 --- a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java +++ b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java @@ -133,9 +133,10 @@ public class EndToEndTest { new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), new ParameterizedTypeReference>() {}).getBody(); - AccountTransactionInfo expectedTransactionInfo = new AccountTransactionInfo(moneyTransfer.getMoneyTransferId(), fromAccountId, toAccountId, toCents(amountToTransfer).longValue()); - - assertTrue(transactionInfoList.contains(expectedTransactionInfo)); + assertTrue(transactionInfoList.stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId()) && + ti.getFromAccountId().equals(fromAccountId) && + ti.getToAccountId().equals(toAccountId) && + ti.getAmount() == toCents(amountToTransfer).longValue()).findFirst().isPresent()); } @Test From 9276b1bdc839d42b39f4bbc866e54835d4469ade Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 22 Mar 2016 19:49:09 +0300 Subject: [PATCH 6/6] changed return result for empty accounts case --- .../backend/queryside/accounts/AccountQueryService.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryService.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryService.java index 0e4bc45..6e4e783 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryService.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQueryService.java @@ -1,9 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; -import net.chrisrichardson.eventstore.Aggregate; import net.chrisrichardson.eventstore.EntityIdentifier; -import net.chrisrichardson.eventstore.EntityNotFoundException; -import org.springframework.dao.EmptyResultDataAccessException; import rx.Observable; import java.util.List; @@ -25,10 +22,6 @@ public class AccountQueryService { } public Observable> findByCustomerId(String customerId) { - List result = accountInfoRepository.findByCustomerId(customerId); - if(result.isEmpty()) - return Observable.error(new EmptyResultDataAccessException(1)); - else - return Observable.just(result); + return Observable.just(accountInfoRepository.findByCustomerId(customerId)); } }