From f570ccbe908509c0a17cf597ac27f6e94c746a76 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Fri, 5 Aug 2016 16:41:16 -0700 Subject: [PATCH 1/8] Support for Eventuate Local --- _build-and-test-all.sh | 7 ++ .../build.gradle | 4 +- .../accounts-query-side-service/build.gradle | 3 +- java-spring/api-gateway-service/build.gradle | 4 +- .../groovy/EventuateDependencyPlugin.groovy | 15 +++ .../build.gradle | 3 +- .../customers-query-side-service/build.gradle | 3 +- .../docker-compose-eventuate-local.yml | 111 ++++++++++++++++++ java-spring/gradle.properties | 1 + .../build.gradle | 3 +- 10 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy create mode 100644 java-spring/docker-compose-eventuate-local.yml diff --git a/_build-and-test-all.sh b/_build-and-test-all.sh index 8258cf0..a7b884c 100755 --- a/_build-and-test-all.sh +++ b/_build-and-test-all.sh @@ -6,6 +6,12 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DOCKER_COMPOSE="docker-compose -p event-sourcing-examples" +if [ "$1" = "-f" ] ; then + shift; + DOCKER_COMPOSE="$DOCKER_COMPOSE -f ${1?}" + shift +fi + if [ "$1" = "--use-existing" ] ; then shift; else @@ -13,6 +19,7 @@ else ${DOCKER_COMPOSE?} rm -v --force fi + ${DOCKER_COMPOSE?} up -d mongodb if [ -z "$DOCKER_HOST_IP" ] ; then diff --git a/java-spring/accounts-command-side-service/build.gradle b/java-spring/accounts-command-side-service/build.gradle index 680bc18..19b152b 100644 --- a/java-spring/accounts-command-side-service/build.gradle +++ b/java-spring/accounts-command-side-service/build.gradle @@ -1,5 +1,6 @@ apply plugin: VerifyMongoDBConfigurationPlugin apply plugin: VerifyEventStoreEnvironmentPlugin +apply plugin: EventuateDependencyPlugin apply plugin: 'spring-boot' @@ -10,9 +11,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile "org.springframework.boot:spring-boot-starter-test" } diff --git a/java-spring/accounts-query-side-service/build.gradle b/java-spring/accounts-query-side-service/build.gradle index 1d80761..67ac6a5 100644 --- a/java-spring/accounts-query-side-service/build.gradle +++ b/java-spring/accounts-query-side-service/build.gradle @@ -1,5 +1,6 @@ apply plugin: VerifyMongoDBConfigurationPlugin apply plugin: VerifyEventStoreEnvironmentPlugin +apply plugin: EventuateDependencyPlugin apply plugin: 'spring-boot' @@ -10,8 +11,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile project(":testutil") testCompile "org.springframework.boot:spring-boot-starter-test" diff --git a/java-spring/api-gateway-service/build.gradle b/java-spring/api-gateway-service/build.gradle index 12c64f2..7d9d7c4 100644 --- a/java-spring/api-gateway-service/build.gradle +++ b/java-spring/api-gateway-service/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'java' apply plugin: 'spring-boot' +apply plugin: EventuateDependencyPlugin dependencies { compile project(":common-auth-web") @@ -7,9 +8,6 @@ dependencies { compile "org.apache.httpcomponents:httpclient:4.5" compile "org.apache.httpcomponents:fluent-hc:4.5.1" - compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion" - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion" diff --git a/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy b/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy new file mode 100644 index 0000000..4a7804a --- /dev/null +++ b/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy @@ -0,0 +1,15 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project + +class EventuateDependencyPlugin implements Plugin { + + @Override + void apply(Project project) { + project.dependencies { + if (project.hasProperty("eventuateLocal")) + compile "io.eventuate.local.java:eventuate-local-java-jdbc:${project.eventuateLocalVersion}" + else + compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:${project.eventuateClientVersion}" + } + } +} diff --git a/java-spring/customers-command-side-service/build.gradle b/java-spring/customers-command-side-service/build.gradle index 47956f1..186647d 100644 --- a/java-spring/customers-command-side-service/build.gradle +++ b/java-spring/customers-command-side-service/build.gradle @@ -2,6 +2,7 @@ apply plugin: VerifyMongoDBConfigurationPlugin apply plugin: VerifyEventStoreEnvironmentPlugin apply plugin: 'spring-boot' +apply plugin: EventuateDependencyPlugin dependencies { compile project(":customers-command-side-web") @@ -10,8 +11,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile project(":testutil-customers") testCompile "org.springframework.boot:spring-boot-starter-test" } \ No newline at end of file diff --git a/java-spring/customers-query-side-service/build.gradle b/java-spring/customers-query-side-service/build.gradle index 17a98ff..409b0e3 100644 --- a/java-spring/customers-query-side-service/build.gradle +++ b/java-spring/customers-query-side-service/build.gradle @@ -1,5 +1,6 @@ apply plugin: VerifyMongoDBConfigurationPlugin apply plugin: VerifyEventStoreEnvironmentPlugin +apply plugin: EventuateDependencyPlugin apply plugin: 'spring-boot' @@ -10,8 +11,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile project(":testutil-customers") testCompile project(":customers-command-side-service") testCompile "org.springframework.boot:spring-boot-starter-test" diff --git a/java-spring/docker-compose-eventuate-local.yml b/java-spring/docker-compose-eventuate-local.yml new file mode 100644 index 0000000..d0f9a75 --- /dev/null +++ b/java-spring/docker-compose-eventuate-local.yml @@ -0,0 +1,111 @@ +apigateway: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./api-gateway-service/build/libs:/app + command: java -jar /app/api-gateway-service.jar --accounts.commandside.service.host=accountscommandside --transactions.commandside.service.host=transactionscommandside --accounts.queryside.service.host=accountsqueryside --customers.commandside.service.host=customerscommandside --customers.queryside.service.host=customersqueryside + ports: + - "8080:8080" + links: + - accountscommandside + - transactionscommandside + - accountsqueryside + - customerscommandside + - customersqueryside + - mongodb + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + +accountscommandside: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./accounts-command-side-service/build/libs:/app + command: java -jar /app/accounts-command-side-service.jar + ports: + - "8085:8080" + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + +transactionscommandside: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./transactions-command-side-service/build/libs:/app + command: java -jar /app/transactions-command-side-service.jar + ports: + - "8082:8080" + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + + +accountsqueryside: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./accounts-query-side-service/build/libs:/app + command: java -jar /app/accounts-query-side-service.jar + ports: + - "8081:8080" + links: + - mongodb + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + +customerscommandside: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./customers-command-side-service/build/libs:/app + command: java -jar /app/customers-command-side-service.jar + ports: + - "8083:8080" + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + +customersqueryside: + image: java:openjdk-8u91-jdk + working_dir: /app + volumes: + - ./customers-query-side-service/build/libs:/app + command: java -jar /app/customers-query-side-service.jar + ports: + - "8084:8080" + links: + - mongodb + environment: + SPRING_DATASOURCE_URL: + SPRING_DATASOURCE_USERNAME: + SPRING_DATASOURCE_PASSWORD: + SPRING_DATASOURCE_DRIVER_CLASS_NAME: + EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + +mongodb: + image: mongo:3.0.4 + hostname: mongodb + command: mongod --smallfiles + ports: + - "27017:27017" diff --git a/java-spring/gradle.properties b/java-spring/gradle.properties index 5be6652..f4896e4 100644 --- a/java-spring/gradle.properties +++ b/java-spring/gradle.properties @@ -6,4 +6,5 @@ eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release springBootVersion=1.3.5.RELEASE eventuateClientVersion=0.2.0.RELEASE +eventuateLocalVersion=0.1.0.RELEASE diff --git a/java-spring/transactions-command-side-service/build.gradle b/java-spring/transactions-command-side-service/build.gradle index 5e13adb..3d530db 100644 --- a/java-spring/transactions-command-side-service/build.gradle +++ b/java-spring/transactions-command-side-service/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'spring-boot' +apply plugin: EventuateDependencyPlugin apply plugin: VerifyEventStoreEnvironmentPlugin @@ -9,8 +10,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion" - testCompile "org.springframework.boot:spring-boot-starter-test" } From bd3de1a9385eda2f92d5361a05ccd0351064d8dd Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Sat, 6 Aug 2016 13:26:08 -0700 Subject: [PATCH 2/8] Bumped version --- java-spring/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-spring/gradle.properties b/java-spring/gradle.properties index f4896e4..c155186 100644 --- a/java-spring/gradle.properties +++ b/java-spring/gradle.properties @@ -5,6 +5,6 @@ eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release springBootVersion=1.3.5.RELEASE -eventuateClientVersion=0.2.0.RELEASE +eventuateClientVersion=0.6.0.RELEASE eventuateLocalVersion=0.1.0.RELEASE From f4e070e7bd5b4d8918dc5991f12204d8230c4bf2 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Thu, 18 Aug 2016 13:53:04 -0700 Subject: [PATCH 3/8] Upgraded to Eventuate Local 0.2.0.RELEASE --- _build-and-test-all.sh | 12 ++- .../queryside/accounts/AccountChangeInfo.java | 13 +++ .../queryside/accounts/AccountInfo.java | 11 ++- .../accounts/AccountInfoUpdateService.java | 29 +++--- .../accounts/AccountTransactionInfo.java | 7 ++ .../QuerySideAccountConfiguration.java | 4 +- .../AccountInfoUpdateServiceTest.java | 96 +++++++++++++++++++ .../backend/BankingTestConfiguration.java | 2 + .../groovy/EventuateDependencyPlugin.groovy | 5 +- .../src/main/resources/logback.xml | 2 +- .../docker-compose-eventuate-local.yml | 30 ++++-- .../examples/bank/web/EndToEndTest.java | 38 +++++--- java-spring/gradle.properties | 4 +- .../web/BankingWebIntegrationTest.java | 33 ++++--- .../javaexamples/testutil/TestUtil.java | 2 +- 15 files changed, 226 insertions(+), 62 deletions(-) create mode 100644 java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java diff --git a/_build-and-test-all.sh b/_build-and-test-all.sh index a7b884c..e981415 100755 --- a/_build-and-test-all.sh +++ b/_build-and-test-all.sh @@ -19,6 +19,12 @@ else ${DOCKER_COMPOSE?} rm -v --force fi +NO_RM=false + +if [ "$1" = "--no-rm" ] ; then + NO_RM=true + shift +fi ${DOCKER_COMPOSE?} up -d mongodb @@ -54,5 +60,7 @@ set -e ./gradlew -a $* :e2e-test:cleanTest :e2e-test:test -P ignoreE2EFailures=false -${DOCKER_COMPOSE?} stop -${DOCKER_COMPOSE?} rm -v --force +if [ $NO_RM = false ] ; then + ${DOCKER_COMPOSE?} stop + ${DOCKER_COMPOSE?} rm -v --force +fi diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountChangeInfo.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountChangeInfo.java index b9ccf0d..b988eb1 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountChangeInfo.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountChangeInfo.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 AccountChangeInfo { private String changeId; @@ -15,4 +18,14 @@ public class AccountChangeInfo { this.amount = amount; this.balanceDelta = balanceDelta; } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } 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..5a25615 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,6 +1,9 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; /** * Created by cer on 11/21/14. @@ -13,13 +16,13 @@ public class AccountInfo { private String description; private long balance; private List changes; - private List transactions; + private Map transactions; private String version; private AccountInfo() { } - public AccountInfo(String id, String customerId, String title, String description, long balance, List changes, List transactions, String version) { + public AccountInfo(String id, String customerId, String title, String description, long balance, List changes, Map transactions, String version) { this.id = id; this.customerId = customerId; @@ -52,11 +55,11 @@ public class AccountInfo { } public List getChanges() { - return changes; + return changes == null ? Collections.EMPTY_LIST : changes; } public List getTransactions() { - return transactions; + return transactions == null ? Collections.EMPTY_LIST : new ArrayList<>(transactions.values()); } public String getVersion() { 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..834b961 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 @@ -16,11 +16,9 @@ import static org.springframework.data.mongodb.core.query.Criteria.where; public class AccountInfoUpdateService { private Logger logger = LoggerFactory.getLogger(getClass()); - private AccountInfoRepository accountInfoRepository; private MongoTemplate mongoTemplate; - public AccountInfoUpdateService(AccountInfoRepository accountInfoRepository, MongoTemplate mongoTemplate) { - this.accountInfoRepository = accountInfoRepository; + public AccountInfoUpdateService(MongoTemplate mongoTemplate) { this.mongoTemplate = mongoTemplate; } @@ -28,29 +26,26 @@ public class AccountInfoUpdateService { public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, String version) { try { - accountInfoRepository.save(new AccountInfo( - accountId, - customerId, - title, - description, - toIntegerRepr(initialBalance), - Collections.emptyList(), - Collections.emptyList(), - version)); + WriteResult x = mongoTemplate.upsert(new Query(where("id").is(accountId).and("version").exists(false)), + new Update() + .set("customerId", customerId) + .set("title", title) + .set("description", description) + .set("balance", toIntegerRepr(initialBalance)) + .set("version", version), + AccountInfo.class); logger.info("Saved in mongo"); } catch (Throwable t) { - logger.error("Error during saving: "); logger.error("Error during saving: ", t); throw new RuntimeException(t); } } - public void addTransaction(String eventId, String fromAccountId, AccountTransactionInfo ti) { - mongoTemplate.updateMulti(new Query(where("id").is(fromAccountId).and("version").lt(eventId)), + public void addTransaction(String eventId, String accountId, AccountTransactionInfo ti) { + mongoTemplate.upsert(new Query(where("id").is(accountId)), new Update(). - push("transactions", ti). - set("version", eventId), + set("transactions." + eventId, ti), AccountInfo.class); } 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 6a0f9a8..8660536 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 @@ -2,6 +2,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; import java.util.Date; @@ -21,6 +22,12 @@ public class AccountTransactionInfo { this(transactionId, fromAccountId, toAccountId, amount, new Date(), ""); } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount, Date date, String description) { this.transactionId = transactionId; this.fromAccountId = fromAccountId; diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/QuerySideAccountConfiguration.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/QuerySideAccountConfiguration.java index e34e727..018d760 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/QuerySideAccountConfiguration.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/QuerySideAccountConfiguration.java @@ -18,8 +18,8 @@ public class QuerySideAccountConfiguration { } @Bean - public AccountInfoUpdateService accountInfoUpdateService(AccountInfoRepository accountInfoRepository, MongoTemplate mongoTemplate) { - return new AccountInfoUpdateService(accountInfoRepository, mongoTemplate); + public AccountInfoUpdateService accountInfoUpdateService(MongoTemplate mongoTemplate) { + return new AccountInfoUpdateService(mongoTemplate); } @Bean diff --git a/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java b/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java new file mode 100644 index 0000000..fabe490 --- /dev/null +++ b/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java @@ -0,0 +1,96 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts; + +import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration; +import io.eventuate.javaclient.spring.jdbc.IdGenerator; +import io.eventuate.javaclient.spring.jdbc.IdGeneratorImpl; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static org.junit.Assert.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = AccountInfoUpdateServiceTest.AccountInfoUpdateServiceTestConfiguration.class) +@IntegrationTest +public class AccountInfoUpdateServiceTest { + + @Configuration + @EnableAutoConfiguration + @Import({QuerySideAccountConfiguration.class, EventuateJdbcEventStoreConfiguration.class}) + public static class AccountInfoUpdateServiceTestConfiguration { + + } + + @Autowired + private AccountInfoUpdateService accountInfoUpdateService; + + @Autowired + private AccountQueryService accountQueryService; + + @Test + public void shouldSaveAccountInfo() throws ExecutionException, InterruptedException { + IdGenerator x = new IdGeneratorImpl(); + String accountId = x.genId().asString(); + String customerId = x.genId().asString(); + String version = x.genId().asString(); + + String title = "Checking account"; + BigDecimal initialBalance = new BigDecimal("1345"); + String description = "Some account"; + + accountInfoUpdateService.create(accountId, customerId, title, initialBalance, description, version); + + AccountInfo accountInfo = accountQueryService.findByAccountId(accountId).get(); + + assertEquals(accountId, accountInfo.getId()); + assertEquals(customerId, accountInfo.getCustomerId()); + assertEquals(title, accountInfo.getTitle()); + assertEquals(description, accountInfo.getDescription()); + assertEquals(initialBalance.longValue() * 100, accountInfo.getBalance()); + assertTrue(accountInfo.getChanges().isEmpty()); + assertTrue(accountInfo.getTransactions().isEmpty()); + assertEquals(version, accountInfo.getVersion()); + + + String changeId = x.genId().asString(); + + String transactionId = x.genId().asString(); + + AccountChangeInfo change = new AccountChangeInfo(changeId, transactionId, AccountCreditedEvent.class.getSimpleName(), + 500, +1); + + accountInfoUpdateService.updateBalance(accountId, changeId, 500, + change); + + accountInfo = accountQueryService.findByAccountId(accountId).get(); + assertEquals(initialBalance.add(new BigDecimal(5)).longValue() * 100, accountInfo.getBalance()); + assertFalse(accountInfo.getChanges().isEmpty()); + + assertEquals(change, accountInfo.getChanges().get(0)); + + String eventId = x.genId().asString(); + + AccountTransactionInfo ti = new AccountTransactionInfo(transactionId, accountId, accountId, 5, new Date(), "A transfer"); + + accountInfoUpdateService.addTransaction(eventId, accountId, ti); + + accountInfo = accountQueryService.findByAccountId(accountId).get(); + assertFalse(accountInfo.getTransactions().isEmpty()); + + assertEquals(ti, accountInfo.getTransactions().get(0)); + } + +} \ No newline at end of file diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java index 1d252e9..096e451 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java @@ -3,11 +3,13 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend; import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @Configuration @Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class}) +@EnableAutoConfiguration public class BankingTestConfiguration { } diff --git a/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy b/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy index 4a7804a..c531a8c 100644 --- a/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy +++ b/java-spring/buildSrc/src/main/groovy/EventuateDependencyPlugin.groovy @@ -6,9 +6,10 @@ class EventuateDependencyPlugin implements Plugin { @Override void apply(Project project) { project.dependencies { - if (project.hasProperty("eventuateLocal")) + if (project.hasProperty("eventuateLocal")) { compile "io.eventuate.local.java:eventuate-local-java-jdbc:${project.eventuateLocalVersion}" - else + compile "io.eventuate.local.java:eventuate-local-java-embedded-cdc-autoconfigure:${project.eventuateLocalVersion}" + } else compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:${project.eventuateClientVersion}" } } diff --git a/java-spring/common-backend/src/main/resources/logback.xml b/java-spring/common-backend/src/main/resources/logback.xml index d4123dc..ce0479c 100644 --- a/java-spring/common-backend/src/main/resources/logback.xml +++ b/java-spring/common-backend/src/main/resources/logback.xml @@ -16,7 +16,7 @@ - + diff --git a/java-spring/docker-compose-eventuate-local.yml b/java-spring/docker-compose-eventuate-local.yml index d0f9a75..0f347d8 100644 --- a/java-spring/docker-compose-eventuate-local.yml +++ b/java-spring/docker-compose-eventuate-local.yml @@ -18,8 +18,11 @@ apigateway: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: accountscommandside: image: java:openjdk-8u91-jdk @@ -34,7 +37,10 @@ accountscommandside: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: transactionscommandside: image: java:openjdk-8u91-jdk @@ -49,7 +55,10 @@ transactionscommandside: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: accountsqueryside: @@ -67,8 +76,11 @@ accountsqueryside: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: customerscommandside: image: java:openjdk-8u91-jdk @@ -83,7 +95,10 @@ customerscommandside: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: customersqueryside: image: java:openjdk-8u91-jdk @@ -100,8 +115,11 @@ customersqueryside: SPRING_DATASOURCE_USERNAME: SPRING_DATASOURCE_PASSWORD: SPRING_DATASOURCE_DRIVER_CLASS_NAME: - EVENTUATELOCAL_AGGREGATESTORE_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_KAFKA_BOOTSTRAP_SERVERS: + EVENTUATELOCAL_ZOOKEEPER_CONNECTION_STRING: SPRING_DATA_MONGODB_URI: mongodb://mongodb/mydb + EVENTUATELOCAL_EMBEDDED_CDC_DB_USER_NAME: + EVENTUATELOCAL_EMBEDDED_CDC_DB_PASSWORD: mongodb: image: mongo:3.0.4 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..0c2cd64 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 @@ -28,6 +28,7 @@ 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 org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class EndToEndTest { @@ -115,15 +116,26 @@ public class EndToEndTest { // 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(); + eventually( + () -> CompletableFuture.completedFuture(restTemplate.exchange(accountsQuerySideBaseUrl("/accounts/"+fromAccountId+"/history"), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody()), + transactionInfoList -> { + if (!(transactionInfoList.stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId()) && + ti.getFromAccountId().equals(fromAccountId) && + ti.getToAccountId().equals(toAccountId) && + ti.getAmount() == toCents(amountToTransfer).longValue()).findFirst().isPresent())) { + fail(String.format("%s does not contain %s %s %s", + moneyTransfer.getMoneyTransferId(), + fromAccount, + toAccount, + toCents(amountToTransfer).longValue())); + } + + } + ); - 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 @@ -163,14 +175,14 @@ public class EndToEndTest { return dollarAmount.multiply(new BigDecimal(100)); } - private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { + private void assertAccountBalance(final String accountId, final BigDecimal expectedBalanceInDollars) { final BigDecimal inCents = toCents(expectedBalanceInDollars); - eventually( + eventually( new Producer() { @Override public CompletableFuture produce() { return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - accountsQuerySideBaseUrl("/accounts/" + fromAccountId), + accountsQuerySideBaseUrl("/accounts/" + accountId), HttpMethod.GET, GetAccountResponse.class)); } @@ -178,8 +190,8 @@ public class EndToEndTest { new Verifier() { @Override public void verify(GetAccountResponse accountInfo) { - Assert.assertEquals(fromAccountId, accountInfo.getAccountId()); - Assert.assertEquals(inCents, accountInfo.getBalance()); + Assert.assertEquals(accountId, accountInfo.getAccountId()); + Assert.assertEquals(accountId, inCents, accountInfo.getBalance()); } }); } diff --git a/java-spring/gradle.properties b/java-spring/gradle.properties index c155186..8c03167 100644 --- a/java-spring/gradle.properties +++ b/java-spring/gradle.properties @@ -5,6 +5,6 @@ eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release springBootVersion=1.3.5.RELEASE -eventuateClientVersion=0.6.0.RELEASE -eventuateLocalVersion=0.1.0.RELEASE +eventuateClientVersion=0.8.0.RELEASE +eventuateLocalVersion=0.2.0.RELEASE 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 f9ea3b1..f222860 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 @@ -35,6 +35,7 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customer import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateToAccountInfo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class) @@ -102,23 +103,31 @@ 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(); + eventually( + () -> CompletableFuture.completedFuture(restTemplate.exchange(baseUrl("/accounts/"+fromAccountId+"/history"), + HttpMethod.GET, + new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), + new ParameterizedTypeReference>() {}).getBody()), + transactionInfoList -> { + Optional txn = transactionInfoList.stream() + .filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId())) + .findFirst(); - Optional first = transactionInfoList.stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId())).findFirst(); + if (!txn.isPresent()) { + fail(String.format("%s does not contain %s", transactionInfoList, moneyTransfer.getMoneyTransferId())); + } - assertTrue(first.isPresent()); + AccountTransactionInfo ti = txn.get(); - 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()); + } + ); - assertEquals(fromAccountId, ti.getFromAccountId()); - assertEquals(toAccountId, ti.getToAccountId()); - assertEquals(toAccountId, ti.getToAccountId()); - assertEquals(fromAccountId, ti.getFromAccountId()); - assertEquals(toCents(amountToTransfer).longValue(), ti.getAmount()); } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java index f39dfe7..b8f8307 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java @@ -55,7 +55,7 @@ public class TestUtil { } public static void eventually(final Producer producer, final Verifier verifier) { - final int n = 50; + final int n = 150; Object possibleException = Observable.timer(0, 200, TimeUnit.MILLISECONDS).flatMap(new Func1>>() { @Override From f4ec33d27542c5316e35affced64239ffbda18f4 Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 30 Aug 2016 19:07:57 +0300 Subject: [PATCH 4/8] Merge remote-tracking branch 'remotes/upstream/wip-eventuate-local' into wip-customer --- .../queryside/accounts/AccountInfo.java | 2 + .../AccountInfoUpdateServiceTest.java | 1 + .../build.gradle | 2 +- .../customers-query-side-service/build.gradle | 2 +- ...tomersQuerySideServiceIntegrationTest.java | 7 + ...mersQuerySideServiceTestConfiguration.java | 4 +- .../examples/bank/web/EndToEndTest.java | 192 ++---------------- .../banking/web/BankingAuthTest.java | 6 + .../web/BankingWebIntegrationTest.java | 31 +-- .../testutil/AbstractRestAPITest.java | 12 ++ .../testutil/CustomersTestUtils.java | 1 + .../javaexamples/testutil/TestUtil.java | 15 ++ 12 files changed, 69 insertions(+), 206 deletions(-) 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 5a25615..51fa5a1 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.ArrayList; import java.util.Collections; import java.util.List; diff --git a/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java b/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java index fabe490..2b7baec 100644 --- a/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java +++ b/java-spring/accounts-query-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateServiceTest.java @@ -4,6 +4,7 @@ import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration; import io.eventuate.javaclient.spring.jdbc.IdGenerator; import io.eventuate.javaclient.spring.jdbc.IdGeneratorImpl; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent; +import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/java-spring/customers-command-side-service/build.gradle b/java-spring/customers-command-side-service/build.gradle index 186647d..e0f8251 100644 --- a/java-spring/customers-command-side-service/build.gradle +++ b/java-spring/customers-command-side-service/build.gradle @@ -11,6 +11,6 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - 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-query-side-service/build.gradle b/java-spring/customers-query-side-service/build.gradle index 409b0e3..6b218bb 100644 --- a/java-spring/customers-query-side-service/build.gradle +++ b/java-spring/customers-query-side-service/build.gradle @@ -11,7 +11,7 @@ dependencies { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" - 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/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceIntegrationTest.java b/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceIntegrationTest.java index bb7b602..fb4cd23 100644 --- a/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceIntegrationTest.java +++ b/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceIntegrationTest.java @@ -2,6 +2,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*; import net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils; +import org.apache.tomcat.jni.Thread; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,6 +51,12 @@ public class CustomersQuerySideServiceIntegrationTest { final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); final String customerId = customerResponse.getId(); + try { + java.lang.Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + customersTestUtils.assertCustomerResponse(customerId, customerInfo); } diff --git a/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceTestConfiguration.java b/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceTestConfiguration.java index ea020df..cb17c0c 100644 --- a/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceTestConfiguration.java +++ b/java-spring/customers-query-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersQuerySideServiceTestConfiguration.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,7 +14,8 @@ import java.util.Arrays; import java.util.List; @Configuration -@Import({CustomersQuerySideServiceConfiguration.class, CustomersQuerySideServiceConfiguration.class, AuthConfiguration.class}) +@Import({CustomersCommandSideServiceConfiguration.class, CustomersQuerySideServiceConfiguration.class, AuthConfiguration.class}) +@EnableAutoConfiguration public class CustomersQuerySideServiceTestConfiguration { @Bean 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 0c2cd64..29684ab 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,199 +1,39 @@ 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 net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils; import org.springframework.web.client.RestTemplate; -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 org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class EndToEndTest { +public class EndToEndTest extends AbstractRestAPITest { private String getenv(String name, String defaultValue) { String x = System.getenv(name); return x == null ? defaultValue : x; } - private String makeBaseUrl(int port, String path) { - return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + port + "/" + path; - } - - 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 - - eventually( - () -> CompletableFuture.completedFuture(restTemplate.exchange(accountsQuerySideBaseUrl("/accounts/"+fromAccountId+"/history"), - HttpMethod.GET, - new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")), - new ParameterizedTypeReference>() {}).getBody()), - transactionInfoList -> { - if (!(transactionInfoList.stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId()) && - ti.getFromAccountId().equals(fromAccountId) && - ti.getToAccountId().equals(toAccountId) && - ti.getAmount() == toCents(amountToTransfer).longValue()).findFirst().isPresent())) { - fail(String.format("%s does not contain %s %s %s", - moneyTransfer.getMoneyTransferId(), - fromAccount, - toAccount, - toCents(amountToTransfer).longValue())); - } - - } - ); + CustomersTestUtils customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); + public String baseUrl(String path) { + return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + 8080 + "/" + path; } - @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()); + @Override + public CustomersTestUtils getCustomersTestUtils() { + return customersTestUtils; } - private BigDecimal toCents(BigDecimal dollarAmount) { - return dollarAmount.multiply(new BigDecimal(100)); + @Override + public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { + return new AuthenticatedRestTemplate(restTemplate); } - private void assertAccountBalance(final String accountId, final BigDecimal expectedBalanceInDollars) { - final BigDecimal inCents = toCents(expectedBalanceInDollars); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - accountsQuerySideBaseUrl("/accounts/" + accountId), - HttpMethod.GET, - GetAccountResponse.class)); - } - }, - new Verifier() { - @Override - public void verify(GetAccountResponse accountInfo) { - Assert.assertEquals(accountId, accountInfo.getAccountId()); - Assert.assertEquals(accountId, inCents, accountInfo.getBalance()); - } - }); + @Override + public RestTemplate getRestTemplate() { + return restTemplate; } } diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java index bb03f31..173f31d 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java @@ -57,6 +57,12 @@ public class BankingAuthTest { Assert.assertNotNull(customerId); Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + customersTestUtils.assertCustomerResponse(customerId, customerInfo); AuthRequest authRequest = new AuthRequest(email); 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 b57b3f1..f07ac9d 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,41 +1,18 @@ 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 net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils; 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.Optional; -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.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class) 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 index a780590..6055ed1 100644 --- 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 @@ -51,6 +51,12 @@ public abstract class AbstractRestAPITest { Assert.assertNotNull(fromAccountId); Assert.assertNotNull(toAccountId); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + assertAccountBalance(fromAccountId, initialFromAccountBalance); assertAccountBalance(toAccountId, initialToAccountBalance); @@ -98,6 +104,12 @@ public abstract class AbstractRestAPITest { Assert.assertNotNull(customerId); assertEquals(customerInfo, customerResponse.getCustomerInfo()); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); final CreateAccountResponse account = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java index a9e6e6e..4fc4fe1 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java @@ -6,6 +6,7 @@ import org.springframework.web.client.RestTemplate; import java.util.concurrent.CompletableFuture; +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.awaitSuccessfulRequest; import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; /** diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java index 0a301a2..025cdb1 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java @@ -1,5 +1,7 @@ package net.chrisrichardson.eventstorestore.javaexamples.testutil; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import rx.Observable; import rx.Subscriber; import rx.functions.Action1; @@ -11,6 +13,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Supplier; public class TestUtil { @@ -22,6 +25,18 @@ public class TestUtil { } } + public static T awaitSuccessfulRequest(Supplier> func, Func1 predicate) { + try { + return Observable.interval(400, TimeUnit.MILLISECONDS) + .take(50) + .map(x -> func.get()) + .filter(re -> re.getStatusCode().equals(HttpStatus.OK) && re.getBody() != null && predicate.call(re.getBody())) + .toBlocking().first().getBody(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + static class Tuple2 { private A first; From 2467099c3e732ae69045bc2e0c88c5fc941e7ffa Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 30 Aug 2016 19:14:03 +0300 Subject: [PATCH 5/8] -changed path to UI static content --- java-spring/api-gateway-service/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-spring/api-gateway-service/build.gradle b/java-spring/api-gateway-service/build.gradle index 7d9d7c4..9936529 100644 --- a/java-spring/api-gateway-service/build.gradle +++ b/java-spring/api-gateway-service/build.gradle @@ -15,7 +15,7 @@ dependencies { } task copyWebStatic(type: Copy) { - from "../../prebuilt-web-client" + from "../../js-frontend/build" into "build/resources/main/static" } From 1e13d482a8dfbd96de0b7165ae32a427de57ceee Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 30 Aug 2016 22:37:55 +0300 Subject: [PATCH 6/8] - disable vertx file cache --- .../javaexamples/banking/web/BankingWebConfiguration.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java index 63bc6d9..ffe415b 100644 --- a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java +++ b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java @@ -14,6 +14,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; @@ -32,6 +33,12 @@ public class BankingWebConfiguration extends WebMvcConfigurerAdapter { return new HttpMessageConverters(additional); } + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + System.setProperty("vertx.disableFileCPResolving", "true"); + return new PropertySourcesPlaceholderConfigurer(); + } + @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("forward:/index.html"); From 1d14ece9cfa575e74f76bb57c3f672bdf64bfc0a Mon Sep 17 00:00:00 2001 From: dartpopikyardo Date: Tue, 30 Aug 2016 23:13:32 +0300 Subject: [PATCH 7/8] - fixed test config --- .../customers-command-side-service/build.gradle | 1 + ...ustomersCommandSideServiceTestConfiguration.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/java-spring/customers-command-side-service/build.gradle b/java-spring/customers-command-side-service/build.gradle index e0f8251..8fd432f 100644 --- a/java-spring/customers-command-side-service/build.gradle +++ b/java-spring/customers-command-side-service/build.gradle @@ -13,4 +13,5 @@ dependencies { testCompile project(":testutil") testCompile "org.springframework.boot:spring-boot-starter-test" + testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion" } \ No newline at end of file diff --git a/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceTestConfiguration.java b/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceTestConfiguration.java index a8f0e44..0fa58b0 100644 --- a/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceTestConfiguration.java +++ b/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceTestConfiguration.java @@ -1,6 +1,10 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; +import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration; +import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration; +import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CustomersCommandSideWebConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,9 +17,16 @@ import java.util.Arrays; import java.util.List; @Configuration -@Import({CustomersCommandSideServiceConfiguration.class, AuthConfiguration.class}) +@Import({CustomersCommandSideWebConfiguration.class, EventuateJdbcEventStoreConfiguration.class, CommonSwaggerConfiguration.class, AuthConfiguration.class}) +@EnableAutoConfiguration public class CustomersCommandSideServiceTestConfiguration { + @Bean + public HttpMessageConverters customConverters() { + HttpMessageConverter additional = new MappingJackson2HttpMessageConverter(); + return new HttpMessageConverters(additional); + } + @Bean public RestTemplate restTemplate(HttpMessageConverters converters) { RestTemplate restTemplate = new RestTemplate(); From e14787bce85f12d47570edf256f1bebc249b885a Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Tue, 30 Aug 2016 16:26:21 -0700 Subject: [PATCH 8/8] Fixed misc @Configuration issues and commented out incorrect version check that causing failure in AccountInfoUpdateService --- .../backend/queryside/accounts/AccountInfoUpdateService.java | 2 +- .../javaexamples/banking/backend/BankingTestConfiguration.java | 2 ++ .../javaexamples/banking/web/BankingWebConfiguration.java | 1 - .../javaexamples/banking/web/BankingWebTestConfiguration.java | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) 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 f0a7832..ecc47fb 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 @@ -47,7 +47,7 @@ public class AccountInfoUpdateService { public void addTransaction(String eventId, String fromAccountId, AccountTransactionInfo ti) { - mongoTemplate.updateMulti(new Query(where("id").is(fromAccountId).and("version").lt(eventId)), + mongoTemplate.updateMulti(new Query(where("id").is(fromAccountId)), /* wrong .and("version").lt(eventId) */ new Update(). push("transactions", ti). set("version", eventId), diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java index 1d252e9..a203e94 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/BankingTestConfiguration.java @@ -5,9 +5,11 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.a import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @Configuration @Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class}) +@EnableAutoConfiguration public class BankingTestConfiguration { } diff --git a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java index 63bc6d9..5b3f7f0 100644 --- a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java +++ b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java @@ -22,7 +22,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Configuration @Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateHttpStompClientConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class}) @EnableAutoConfiguration -@ComponentScan public class BankingWebConfiguration extends WebMvcConfigurerAdapter { diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebTestConfiguration.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebTestConfiguration.java index d32d8ea..c91f07d 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebTestConfiguration.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebTestConfiguration.java @@ -27,7 +27,6 @@ import java.util.List; @Configuration @Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class}) @EnableAutoConfiguration -@ComponentScan public class BankingWebTestConfiguration extends WebMvcConfigurerAdapter { @Bean