diff --git a/java-spring/accounts-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsCommandSideServiceIntegrationTest.java b/java-spring/accounts-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsCommandSideServiceIntegrationTest.java index 0cd5e2e..29ffb9e 100644 --- a/java-spring/accounts-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsCommandSideServiceIntegrationTest.java +++ b/java-spring/accounts-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsCommandSideServiceIntegrationTest.java @@ -1,7 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountRequest; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/AccountController.java b/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/AccountController.java index 2d29e60..f908622 100644 --- a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/AccountController.java +++ b/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/AccountController.java @@ -1,6 +1,8 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfo.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfo.java index 1ed1de4..31d54ae 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfo.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfo.java @@ -1,5 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; + import java.util.List; /** diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java index e7e52d3..af71826 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; import com.mongodb.WriteResult; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.mongodb.core.MongoTemplate; 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 4ac7177..047e894 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 @@ -8,6 +8,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accoun import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/java-spring/accounts-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsQuerySideServiceIntegrationTest.java b/java-spring/accounts-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsQuerySideServiceIntegrationTest.java index 3fbf152..dab85cd 100644 --- a/java-spring/accounts-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsQuerySideServiceIntegrationTest.java +++ b/java-spring/accounts-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/AccountsQuerySideServiceIntegrationTest.java @@ -1,6 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; -import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.GetAccountResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java b/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java index 6cade59..3521389 100644 --- a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java +++ b/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/AccountQueryController.java @@ -4,7 +4,8 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.acc import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService; -import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountTransactionInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.GetAccountResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; diff --git a/java-spring/backend-integration-tests/build.gradle b/java-spring/backend-integration-tests/build.gradle index dfed141..794cdbf 100644 --- a/java-spring/backend-integration-tests/build.gradle +++ b/java-spring/backend-integration-tests/build.gradle @@ -7,7 +7,7 @@ dependencies { testCompile project(":accounts-query-side-backend") testCompile project(":customers-command-side-backend") testCompile project(":customers-query-side-backend") - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile "junit:junit:4.11" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" diff --git a/java-spring/common-auth-web/build.gradle b/java-spring/common-auth-web/build.gradle index be9bc1b..168511d 100644 --- a/java-spring/common-auth-web/build.gradle +++ b/java-spring/common-auth-web/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java' dependencies { compile project(":common-auth") - compile project(":common-customers") + compile project(":common") compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" compile "org.springframework.boot:spring-boot-starter-security:$springBootVersion" diff --git a/java-spring/common-auth/build.gradle b/java-spring/common-auth/build.gradle index 5c316e9..c1bd93a 100644 --- a/java-spring/common-auth/build.gradle +++ b/java-spring/common-auth/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java' dependencies { - compile project(":common-customers") + compile project(":common") compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion" diff --git a/java-spring/common-backend/build.gradle b/java-spring/common-backend/build.gradle index 2599880..b0df157 100644 --- a/java-spring/common-backend/build.gradle +++ b/java-spring/common-backend/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java' dependencies { - compile project(":common-customers") + compile project(":common") compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion" diff --git a/java-spring/common-customers/build.gradle b/java-spring/common/build.gradle similarity index 100% rename from java-spring/common-customers/build.gradle rename to java-spring/common/build.gradle 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/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java similarity index 95% rename from java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java index 6a0f9a8..fd32fc8 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountTransactionInfo.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; +package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; diff --git a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountRequest.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountRequest.java similarity index 93% rename from java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountRequest.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountRequest.java index 46d3f8d..77ddf22 100644 --- a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountRequest.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountRequest.java @@ -1,8 +1,7 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts; +package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts; -import javax.validation.constraints.NotNull; import javax.validation.constraints.DecimalMin; - +import javax.validation.constraints.NotNull; import java.math.BigDecimal; public class CreateAccountRequest { diff --git a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountResponse.java similarity index 80% rename from java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountResponse.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountResponse.java index 781a467..743ba71 100644 --- a/java-spring/accounts-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/accounts/CreateAccountResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/CreateAccountResponse.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts; +package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts; public class CreateAccountResponse { diff --git a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/GetAccountResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java similarity index 92% rename from java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/GetAccountResponse.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java index 129fdd3..a8d10d4 100644 --- a/java-spring/accounts-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/accounts/GetAccountResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts; +package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts; import java.math.BigDecimal; diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java similarity index 100% rename from java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java 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/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferRequest.java similarity index 93% rename from java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferRequest.java index d3c07a6..f82937e 100644 --- a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferRequest.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferRequest.java @@ -1,8 +1,8 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions; +package net.chrisrichardson.eventstore.javaexamples.banking.common.transactions; -import java.math.BigDecimal; -import javax.validation.constraints.NotNull; import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; public class CreateMoneyTransferRequest { diff --git a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferResponse.java similarity index 77% rename from java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferResponse.java rename to java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferResponse.java index 722c642..dfb55be 100644 --- a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/CreateMoneyTransferResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/transactions/CreateMoneyTransferResponse.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions; +package net.chrisrichardson.eventstore.javaexamples.banking.common.transactions; public class CreateMoneyTransferResponse { diff --git a/java-spring/customers-command-side-backend/build.gradle b/java-spring/customers-command-side-backend/build.gradle index d41be06..f633d0e 100644 --- a/java-spring/customers-command-side-backend/build.gradle +++ b/java-spring/customers-command-side-backend/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'java' dependencies { - compile project(":common-customers") + compile project(":common") compile project(":common-backend") compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion" - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile "junit:junit:4.11" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" diff --git a/java-spring/customers-command-side-service/build.gradle b/java-spring/customers-command-side-service/build.gradle index 47956f1..c87805f 100644 --- a/java-spring/customers-command-side-service/build.gradle +++ b/java-spring/customers-command-side-service/build.gradle @@ -12,6 +12,6 @@ dependencies { compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile "org.springframework.boot:spring-boot-starter-test" } \ No newline at end of file diff --git a/java-spring/customers-command-side-web/build.gradle b/java-spring/customers-command-side-web/build.gradle index 8a4057c..18ce48b 100644 --- a/java-spring/customers-command-side-web/build.gradle +++ b/java-spring/customers-command-side-web/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java' dependencies { - compile project(":common-customers") + compile project(":common") compile project(":customers-command-side-backend") compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" diff --git a/java-spring/customers-query-side-service/build.gradle b/java-spring/customers-query-side-service/build.gradle index 17a98ff..a2c245a 100644 --- a/java-spring/customers-query-side-service/build.gradle +++ b/java-spring/customers-query-side-service/build.gradle @@ -12,7 +12,7 @@ dependencies { compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile project(":customers-command-side-service") testCompile "org.springframework.boot:spring-boot-starter-test" } diff --git a/java-spring/e2e-test/build.gradle b/java-spring/e2e-test/build.gradle index 3714086..25e2a75 100644 --- a/java-spring/e2e-test/build.gradle +++ b/java-spring/e2e-test/build.gradle @@ -5,7 +5,7 @@ dependencies { testCompile project(":transactions-command-side-web") testCompile project(":accounts-query-side-web") - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile project(":common-auth") testCompile "junit:junit:4.11" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" 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 9f10477..9590df5 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,187 +1,31 @@ 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; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountRequest; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountResponse; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse; -import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; -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 net.chrisrichardson.eventstorestore.javaexamples.testutil.AbstractRestAPITest; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.AuthenticatedRestTemplate; import org.springframework.web.client.RestTemplate; -import java.math.BigDecimal; -import java.util.List; -import java.util.concurrent.CompletableFuture; +public class EndToEndTest extends AbstractRestAPITest { -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; + private String getenv(String name, String defaultValue) { + String x = System.getenv(name); + return x == null ? defaultValue : x; + } -public class EndToEndTest { + public String baseUrl(String path) { + return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + 8080 + "/" + path; + } - private String getenv(String name, String defaultValue) { - String x = System.getenv(name); - return x == null ? defaultValue : x; - } + RestTemplate restTemplate = new RestTemplate(); - private String makeBaseUrl(int port, String path) { - return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + port + "/" + path; - } + @Override + public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { + return new AuthenticatedRestTemplate(restTemplate); + } - private String accountsCommandSideBaseUrl(String path) { - return makeBaseUrl(8080, path); - } - private String accountsQuerySideBaseUrl(String path) { - return makeBaseUrl(8081, path); - } - private String transactionsCommandSideBaseUrl(String path) { - return makeBaseUrl(8082, path); - } - private String customersCommandSideBaseUrl(String path) { - return makeBaseUrl(8083, path); - } - - private String customersQuerySideBaseUrl(String path) { - return makeBaseUrl(8084, path); - } - - RestTemplate restTemplate = new RestTemplate(); - - CustomersTestUtils customersTestUtils = new CustomersTestUtils(restTemplate, customersQuerySideBaseUrl("/customers/")); - - - @Test - public void shouldCreateCustomerAndAccountsAndTransferMoney() { - CustomerInfo customerInfo = generateCustomerInfo(); - - BigDecimal initialFromAccountBalance = new BigDecimal(500); - BigDecimal initialToAccountBalance = new BigDecimal(100); - BigDecimal amountToTransfer = new BigDecimal(150); - - BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer); - BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer); - - final CustomerResponse customerResponse = restTemplate.postForEntity(customersCommandSideBaseUrl("/customers"),customerInfo, CustomerResponse.class).getBody(); - final String customerId = customerResponse.getId(); - - customersTestUtils.assertCustomerResponse(customerId, customerInfo); - - - final CreateAccountResponse fromAccount = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - accountsCommandSideBaseUrl("/accounts"), - HttpMethod.POST, - CreateAccountResponse.class, - new CreateAccountRequest(customerId, "My #1 Account", "", initialFromAccountBalance) - ); - final String fromAccountId = fromAccount.getAccountId(); - - CreateAccountResponse toAccount = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - accountsCommandSideBaseUrl("/accounts"), - HttpMethod.POST, - CreateAccountResponse.class, - new CreateAccountRequest(customerId, "My #2 Account", "", initialToAccountBalance) - ); - - String toAccountId = toAccount.getAccountId(); - - Assert.assertNotNull(fromAccountId); - Assert.assertNotNull(toAccountId); - - assertAccountBalance(fromAccountId, initialFromAccountBalance); - assertAccountBalance(toAccountId, initialToAccountBalance); - - - final CreateMoneyTransferResponse moneyTransfer = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - transactionsCommandSideBaseUrl("/transfers"), - HttpMethod.POST, - CreateMoneyTransferResponse.class, - new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, "") - ); - - assertAccountBalance(fromAccountId, finalFromAccountBalance); - 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(); - - 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 - 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) { - return dollarAmount.multiply(new BigDecimal(100)); - } - - private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { - final BigDecimal inCents = toCents(expectedBalanceInDollars); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - accountsQuerySideBaseUrl("/accounts/" + fromAccountId), - HttpMethod.GET, - GetAccountResponse.class)); - } - }, - new Verifier() { - @Override - public void verify(GetAccountResponse accountInfo) { - Assert.assertEquals(fromAccountId, accountInfo.getAccountId()); - Assert.assertEquals(inCents, accountInfo.getBalance()); - } - }); - } + @Override + public RestTemplate getRestTemplate() { + return restTemplate; + } } diff --git a/java-spring/monolithic-service/build.gradle b/java-spring/monolithic-service/build.gradle index dc66795..93fb378 100644 --- a/java-spring/monolithic-service/build.gradle +++ b/java-spring/monolithic-service/build.gradle @@ -16,7 +16,7 @@ dependencies { compile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" - testCompile project(":testutil-customers") + testCompile project(":testutil") testCompile "org.springframework.boot:spring-boot-starter-test" } 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 043d52a..6d45e55 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,216 +1,40 @@ 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; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CreateAccountResponse; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse; -import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils; -import org.junit.Assert; -import org.junit.Test; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.AbstractRestAPITest; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.AuthenticatedRestTemplate; import org.junit.runner.RunWith; 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; import org.springframework.web.client.RestTemplate; -import javax.annotation.PostConstruct; -import java.math.BigDecimal; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -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) @WebAppConfiguration @IntegrationTest({"server.port=0", "management.port=0"}) -public class BankingWebIntegrationTest { +public class BankingWebIntegrationTest extends AbstractRestAPITest { @Value("${local.server.port}") private int port; - private String baseUrl(String path) { + @Override + public String baseUrl(String path) { return "http://localhost:" + port + "/" + path; } @Autowired RestTemplate restTemplate; - CustomersTestUtils customersTestUtils; - - @PostConstruct - private void init() { - customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); + @Override + public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { + return new AuthenticatedRestTemplate(restTemplate); } - - @Test - public void shouldCreateAccountsAndTransferMoney() { - BigDecimal initialFromAccountBalance = new BigDecimal(500); - BigDecimal initialToAccountBalance = new BigDecimal(100); - BigDecimal amountToTransfer = new BigDecimal(150); - - BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer); - BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer); - - final CreateAccountResponse fromAccount = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/accounts"), - HttpMethod.POST, - CreateAccountResponse.class, - new CreateAccountRequest("00000000-00000000", "My 1 Account", "", initialFromAccountBalance) - ); - final String fromAccountId = fromAccount.getAccountId(); - - CreateAccountResponse toAccount = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/accounts"), - HttpMethod.POST, - CreateAccountResponse.class, - new CreateAccountRequest("00000000-00000000", "My 2 Account", "", initialToAccountBalance) - ); - - String toAccountId = toAccount.getAccountId(); - - Assert.assertNotNull(fromAccountId); - Assert.assertNotNull(toAccountId); - - assertAccountBalance(fromAccountId, initialFromAccountBalance); - assertAccountBalance(toAccountId, initialToAccountBalance); - - final CreateMoneyTransferResponse moneyTransfer = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/transfers"), - HttpMethod.POST, - CreateMoneyTransferResponse.class, - new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, "") - ); - - 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(); - - - 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 - 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 - public void shouldCreateCustomersAndAddToAccount() { - 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); - - ToAccountInfo toAccountInfo = generateToAccountInfo(); - - BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/customers/"+customerId+"/toaccounts"), - HttpMethod.POST, - null, - toAccountInfo - ); - - assertToAccountsContains(customerId, toAccountInfo); - } - - private BigDecimal toCents(BigDecimal dollarAmount) { - return dollarAmount.multiply(new BigDecimal(100)); - } - - private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { - final BigDecimal inCents = toCents(expectedBalanceInDollars); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/accounts/" + fromAccountId), - HttpMethod.GET, - GetAccountResponse.class)); - } - }, - new Verifier() { - @Override - public void verify(GetAccountResponse accountInfo) { - Assert.assertEquals(fromAccountId, accountInfo.getAccountId()); - Assert.assertEquals(inCents, accountInfo.getBalance()); - } - }); - } - - private void assertToAccountsContains(final String customerId, final ToAccountInfo toAccountInfo) { - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - baseUrl("/customers/" + customerId), - HttpMethod.GET, - QuerySideCustomer.class)); - } - }, - new Verifier() { - @Override - public void verify(QuerySideCustomer customerResponse) { - Assert.assertEquals(customerId, customerResponse.getId()); - assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); - } - }); + @Override + public RestTemplate getRestTemplate() { + return restTemplate; } } diff --git a/java-spring/settings.gradle b/java-spring/settings.gradle index 1d94e96..2c7fd07 100644 --- a/java-spring/settings.gradle +++ b/java-spring/settings.gradle @@ -1,37 +1,35 @@ include 'testutil' +include 'common' +include 'common-backend' +include 'common-auth' +include 'common-auth-web' include 'common-swagger' -include 'common-backend' - include 'accounts-command-side-backend' -include 'transactions-command-side-backend' include 'accounts-command-side-web' -include 'transactions-command-side-web' - +include 'accounts-command-side-service' include 'accounts-query-side-backend' include 'accounts-query-side-web' +include 'accounts-query-side-service' -include 'backend-integration-tests' +include 'transactions-command-side-backend' +include 'transactions-command-side-web' +include 'transactions-command-side-service' + +include 'customers-command-side-backend' +include 'customers-command-side-web' +include 'customers-command-side-service' + +include 'customers-query-side-backend' +include 'customers-query-side-web' +include 'customers-query-side-service' + +include 'api-gateway-service' include 'monolithic-service' -include 'accounts-command-side-service' -include 'accounts-query-side-service' -include 'transactions-command-side-service' - +include 'backend-integration-tests' include 'e2e-test' rootProject.name = 'java-spring-event-sourcing-example' -include 'common-auth' -include 'customers-command-side-backend' -include 'customers-command-side-web' -include 'customers-query-side-backend' -include 'customers-query-side-web' -include 'common-customers' -include 'customers-command-side-service' -include 'customers-query-side-service' -include 'common-auth-web' -include 'api-gateway-service' -include 'testutil-customers' - diff --git a/java-spring/testutil-customers/build.gradle b/java-spring/testutil-customers/build.gradle deleted file mode 100644 index ec3ad28..0000000 --- a/java-spring/testutil-customers/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -apply plugin: 'java' - -dependencies { - compile project(":testutil") - compile project(":common-auth") - compile project(":common-customers") - - compile "io.reactivex:rxjava:1.1.5" - compile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" -} diff --git a/java-spring/testutil/build.gradle b/java-spring/testutil/build.gradle index 403c885..5a16a5e 100644 --- a/java-spring/testutil/build.gradle +++ b/java-spring/testutil/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'java' dependencies { + compile project(":common") + compile project(":common-auth") + compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion" + compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" compile "junit:junit:4.11" compile "io.reactivex:rxjava:1.1.5" - - testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" - testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" - - } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java new file mode 100644 index 0000000..6dfc6b6 --- /dev/null +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java @@ -0,0 +1,202 @@ +package net.chrisrichardson.eventstorestore.javaexamples.testutil; + +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.CreateAccountResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.GetAccountResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.CreateMoneyTransferRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.CreateMoneyTransferResponse; +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.web.client.RestTemplate; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo; +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateToAccountInfo; +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public abstract class AbstractRestAPITest { + + @Test + public void shouldCreateAccountsAndTransferMoney() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + BigDecimal initialToAccountBalance = new BigDecimal(100); + BigDecimal amountToTransfer = new BigDecimal(150); + + BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer); + BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer); + + final CreateAccountResponse fromAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest("00000000-00000000", "My 1 Account", "", initialFromAccountBalance), + CreateAccountResponse.class); + + final String fromAccountId = fromAccount.getAccountId(); + + CreateAccountResponse toAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest("00000000-00000000", "My 2 Account", "", initialToAccountBalance), + CreateAccountResponse.class); + + String toAccountId = toAccount.getAccountId(); + + Assert.assertNotNull(fromAccountId); + Assert.assertNotNull(toAccountId); + + assertAccountBalance(fromAccountId, initialFromAccountBalance); + assertAccountBalance(toAccountId, initialToAccountBalance); + + final CreateMoneyTransferResponse moneyTransfer = getAuthenticatedRestTemplate().postForEntity(baseUrl("/transfers"), + new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, ""), + CreateMoneyTransferResponse.class); + + assertAccountBalance(fromAccountId, finalFromAccountBalance); + assertAccountBalance(toAccountId, finalToAccountBalance); + + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId + "/history"), + AccountTransactionInfo[].class)); + } + }, + new Verifier() { + @Override + public void verify(AccountTransactionInfo[] transactionInfos) { + Optional first = Arrays.asList(transactionInfos).stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId())).findFirst(); + + assertTrue(first.isPresent()); + + AccountTransactionInfo ti = first.get(); + + assertEquals(fromAccountId, ti.getFromAccountId()); + assertEquals(toAccountId, ti.getToAccountId()); + assertEquals(toAccountId, ti.getToAccountId()); + assertEquals(fromAccountId, ti.getFromAccountId()); + assertEquals(toCents(amountToTransfer).longValue(), ti.getAmount()); + } + }); + } + + @Test + public void shouldCreateAccountsAndGetByCustomer() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + CustomerInfo customerInfo = generateCustomerInfo(); + + final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); + + Assert.assertNotNull(customerId); + assertEquals(customerInfo, customerResponse.getCustomerInfo()); + + getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); + + final CreateAccountResponse account = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest(customerId, "My 1 Account", "", initialFromAccountBalance), + CreateAccountResponse.class); + + final String accountId = account.getAccountId(); + + Assert.assertNotNull(accountId); + + assertAccountBalance(accountId, initialFromAccountBalance); + + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts?customerId=" + customerId), + GetAccountResponse[].class)); + } + }, + new Verifier() { + @Override + public void verify(GetAccountResponse[] accountResponses) { + assertTrue(Arrays.asList(accountResponses).stream().filter(acc -> acc.getAccountId().equals(accountId)).findFirst().isPresent()); + } + }); + } + + @Test + public void shouldCreateCustomersAndAddToAccount() { + CustomerInfo customerInfo = generateCustomerInfo(); + + final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); + + Assert.assertNotNull(customerId); + assertEquals(customerInfo, customerResponse.getCustomerInfo()); + + getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); + + ToAccountInfo toAccountInfo = generateToAccountInfo(); + + getAuthenticatedRestTemplate().postForEntity(baseUrl("/customers/" + customerId + "/toaccounts"), + toAccountInfo, + null); + + assertToAccountsContains(customerId, toAccountInfo); + } + + private BigDecimal toCents(BigDecimal dollarAmount) { + return dollarAmount.multiply(new BigDecimal(100)); + } + + private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { + final BigDecimal inCents = toCents(expectedBalanceInDollars); + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId), + GetAccountResponse.class)); + } + }, + new Verifier() { + @Override + public void verify(GetAccountResponse accountInfo) { + assertEquals(fromAccountId, accountInfo.getAccountId()); + assertEquals(inCents, accountInfo.getBalance()); + } + }); + } + + private void assertToAccountsContains(final String customerId, final ToAccountInfo toAccountInfo) { + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/customers/" + customerId), + QuerySideCustomer.class)); + } + }, + new Verifier() { + @Override + public void verify(QuerySideCustomer customerResponse) { + assertEquals(customerId, customerResponse.getId()); + assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); + } + }); + } + + public abstract AuthenticatedRestTemplate getAuthenticatedRestTemplate(); + + public abstract RestTemplate getRestTemplate(); + + public abstract String baseUrl(String path); + + public abstract CustomersTestUtils getCustomersTestUtils(); +} diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java new file mode 100644 index 0000000..f8c55ce --- /dev/null +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java @@ -0,0 +1,30 @@ +package net.chrisrichardson.eventstorestore.javaexamples.testutil; + +import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils; +import org.springframework.http.HttpMethod; +import org.springframework.web.client.RestTemplate; + +public class AuthenticatedRestTemplate { + + private RestTemplate restTemplate; + + public AuthenticatedRestTemplate(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + public T getForEntity(String url, Class clazz) { + return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + url, + HttpMethod.GET, + clazz); + } + + public T postForEntity(String url, Object requestObject, Class clazz) { + return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + url, + HttpMethod.POST, + clazz, + requestObject + ); + } +} diff --git a/java-spring/testutil-customers/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/customers/CustomersTestUtils.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java similarity index 83% rename from java-spring/testutil-customers/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/customers/CustomersTestUtils.java rename to java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java index 2364a53..6d1bdb1 100644 --- a/java-spring/testutil-customers/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/customers/CustomersTestUtils.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java @@ -1,11 +1,7 @@ -package net.chrisrichardson.eventstorestore.javaexamples.testutil.customers; +package net.chrisrichardson.eventstorestore.javaexamples.testutil; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*; -import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; -import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; import org.junit.Assert; -import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import java.util.concurrent.CompletableFuture; @@ -26,14 +22,12 @@ public class CustomersTestUtils { } public void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) { + AuthenticatedRestTemplate art = new AuthenticatedRestTemplate(restTemplate); eventually( new Producer() { @Override public CompletableFuture produce() { - return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - customersBaseUrl + customerId, - HttpMethod.GET, - QuerySideCustomer.class)); + return CompletableFuture.completedFuture(art.getForEntity(customersBaseUrl + customerId, QuerySideCustomer.class)); } }, new Verifier() { @@ -72,6 +66,6 @@ public class CustomersTestUtils { } public static ToAccountInfo generateToAccountInfo() { - return new ToAccountInfo("11111111-11111111", "New Account", "John Doe",""); + return new ToAccountInfo("11111111-11111111", "New Account", "John Doe", ""); } } 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 b25965d..9c353bc 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 @@ -3,6 +3,8 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.tran import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails; +import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.CreateMoneyTransferRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.CreateMoneyTransferResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody;