diff --git a/java-spring/backend-integration-tests/build.gradle b/java-spring/backend-integration-tests/build.gradle index 64a8f56..60d4b97 100644 --- a/java-spring/backend-integration-tests/build.gradle +++ b/java-spring/backend-integration-tests/build.gradle @@ -5,6 +5,8 @@ dependencies { testCompile project(":accounts-command-side-backend") testCompile project(":transactions-command-side-backend") testCompile project(":accounts-query-side-backend") + testCompile project(":customers-command-side-backend") + testCompile project(":customers-query-side-backend") testCompile project(":testutil") testCompile "junit:junit:4.11" testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java new file mode 100644 index 0000000..e92b13a --- /dev/null +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java @@ -0,0 +1,80 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; + +import net.chrisrichardson.eventstore.EntityWithIdAndVersion; +import net.chrisrichardson.eventstore.EventStore; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.Customer; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerService; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import rx.Observable; + +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await; +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; + +/** + * Created by Main on 10.02.2016. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = CustomerQuerySideTestConfiguration.class) +@IntegrationTest +public class CustomerQuerySideIntegrationTest { + + @Autowired + private CustomerService customerService; + + @Autowired + private CustomerQueryService customerQueryService; + + @Autowired + private EventStore eventStore; + + @Test + public void shouldCreateCustomer() throws Exception { + CustomerInfo customerInfo = generateCustomerInfo(); + EntityWithIdAndVersion customer = await(customerService.createCustomer(customerInfo)); + + Thread.sleep(10000); + eventually( + new Producer() { + @Override + public Observable produce() { + return customerQueryService.findByCustomerId(customer.getEntityIdentifier()); + } + }, + new Verifier() { + @Override + public void verify(QuerySideCustomer querySideCustomer) { + Assert.assertEquals(customerInfo.getName(), querySideCustomer.getName()); + Assert.assertEquals(customerInfo.getSsn(), querySideCustomer.getSsn()); + Assert.assertEquals(customerInfo.getEmail(), querySideCustomer.getEmail()); + Assert.assertEquals(customerInfo.getPhoneNumber(), querySideCustomer.getPhoneNumber()); + Assert.assertEquals(customerInfo.getAddress(), querySideCustomer.getAddress()); + } + }); + } + + private CustomerInfo generateCustomerInfo() { + return new CustomerInfo( + new Name("John", "Doe"), + "current@email.com", + "000-00-0000", + "1-111-111-1111", + new Address("street 1", + "street 2", + "City", + "State", + "1111111") + ); + } +} diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideTestConfiguration.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideTestConfiguration.java new file mode 100644 index 0000000..070c50e --- /dev/null +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideTestConfiguration.java @@ -0,0 +1,11 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; + +import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerConfiguration; +import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import({CustomerConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideCustomerConfiguration.class}) +public class CustomerQuerySideTestConfiguration { +} diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java index d1a17b5..b8dc08c 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java @@ -1,46 +1,27 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers; import net.chrisrichardson.eventstore.Event; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; /** * Created by Main on 08.02.2016. */ public class CustomerAddedToAccount implements Event { - private String accountId; - private String accountOwner; - private String title; + private ToAccountInfo toAccountInfo; public CustomerAddedToAccount() { } - public CustomerAddedToAccount(String accountId, String accountOwner, String title) { - this.accountId = accountId; - this.accountOwner = accountOwner; - this.title = title; + public CustomerAddedToAccount( ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; } - public String getAccountId() { - return accountId; + public ToAccountInfo getToAccountInfo() { + return toAccountInfo; } - public void setAccountId(String accountId) { - this.accountId = accountId; - } - - public String getAccountOwner() { - return accountOwner; - } - - public void setAccountOwner(String accountOwner) { - this.accountOwner = accountOwner; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; + public void setToAccountInfo(ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; } } diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java index bfec502..ab719c9 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java @@ -2,22 +2,19 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.custo import net.chrisrichardson.eventstore.Event; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; /** * Created by popikyardo on 02.02.16. */ public class CustomerCreatedEvent implements Event { - private String firstName; - private String lastName; private CustomerInfo customerInfo; public CustomerCreatedEvent() { } - public CustomerCreatedEvent( String firstName, String lastName, CustomerInfo customerInfo) { - this.firstName = firstName; - this.lastName = lastName; + public CustomerCreatedEvent(CustomerInfo customerInfo) { this.customerInfo = customerInfo; } @@ -28,20 +25,4 @@ public class CustomerCreatedEvent implements Event { public void setCustomerInfo(CustomerInfo customerInfo) { this.customerInfo = customerInfo; } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } } diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java index 5ff2097..4f85c42 100644 --- a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java +++ b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java @@ -9,6 +9,7 @@ import javax.validation.constraints.NotNull; * Created by popikyardo on 03.02.16. */ public class CustomerInfo { + private Name name; @NotNull protected String email; @NotNull @@ -20,13 +21,18 @@ public class CustomerInfo { public CustomerInfo() { } - public CustomerInfo(String email, String ssn, String phoneNumber, Address address) { + public CustomerInfo(Name name, String email, String ssn, String phoneNumber, Address address) { + this.name = name; this.email = email; this.ssn = ssn; this.phoneNumber = phoneNumber; this.address = address; } + public Name getName() { + return name; + } + public String getEmail() { return email; } diff --git a/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java new file mode 100644 index 0000000..312363d --- /dev/null +++ b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java @@ -0,0 +1,50 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.common.customers; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import javax.validation.constraints.NotNull; + +/** + * Created by Main on 10.02.2016. + */ +public class Name { + @NotNull + private String firstName; + @NotNull + private String lastName; + + public Name() { + } + + public Name(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } +} diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/ToAccountInfo.java b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java similarity index 84% rename from java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/ToAccountInfo.java rename to java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java index c47f39c..5ca03fe 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/ToAccountInfo.java +++ b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java @@ -1,4 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; +package net.chrisrichardson.eventstore.javaexamples.banking.common.customers; /** diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java index 7cb06c9..5365b2c 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java @@ -1,29 +1,19 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; + /** * Created by Main on 08.02.2016. */ public class AddToAccountCommand implements CustomerCommand { - private String accountId; - private String accountOwner; - private String title; + private ToAccountInfo toAccountInfo; - public AddToAccountCommand(String accountId, String accountOwner, String title) { - this.accountId = accountId; - this.accountOwner = accountOwner; - this.title = title; + public AddToAccountCommand(ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; } - public String getAccountId() { - return accountId; - } - - public String getAccountOwner() { - return accountOwner; - } - - public String getTitle() { - return title; + public ToAccountInfo getToAccountInfo() { + return toAccountInfo; } } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java index 2d51b83..31ea7f8 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java @@ -6,25 +6,13 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust * Created by popikyardo on 02.02.16. */ public class CreateCustomerCommand implements CustomerCommand { - private String firstName; - private String lastName; private CustomerInfo customerInfo; - public CreateCustomerCommand(String firstName, String lastName, CustomerInfo customerInfo) { - this.firstName = firstName; - this.lastName = lastName; + public CreateCustomerCommand(CustomerInfo customerInfo) { this.customerInfo = customerInfo; } public CustomerInfo getCustomerInfo() { return customerInfo; } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java index 7aa74e6..90e6104 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java @@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside. import net.chrisrichardson.eventstore.Event; import net.chrisrichardson.eventstore.EventUtil; import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerAddedToAccount; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; @@ -15,15 +16,21 @@ public class Customer extends ReflectiveMutableCommandProcessingAggregate process(CreateCustomerCommand cmd) { - return EventUtil.events(new CustomerCreatedEvent(cmd.getFirstName(), cmd.getLastName(), cmd.getCustomerInfo())); + return EventUtil.events(new CustomerCreatedEvent(cmd.getCustomerInfo())); + } + + public List process(AddToAccountCommand cmd) { + return EventUtil.events(new CustomerAddedToAccount(cmd.getToAccountInfo())); } public void apply(CustomerCreatedEvent event) { customerInfo = event.getCustomerInfo(); } + public void apply(CustomerAddedToAccount event) { + } + public CustomerInfo getCustomerInfo() { return customerInfo; } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerService.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerService.java index 17bca9f..0a7dfdb 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerService.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerService.java @@ -4,6 +4,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside. import net.chrisrichardson.eventstore.EntityIdentifier; import net.chrisrichardson.eventstore.EntityWithIdAndVersion; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; import net.chrisrichardson.eventstore.repository.AggregateRepository; public class CustomerService { @@ -14,12 +15,12 @@ public class CustomerService { this.accountRepository = accountRepository; } - public rx.Observable> createCustomer(String firstName, String lastName, CustomerInfo customerInfo) { - return accountRepository.save(new CreateCustomerCommand(firstName, lastName, customerInfo)); + public rx.Observable> createCustomer(CustomerInfo customerInfo) { + return accountRepository.save(new CreateCustomerCommand(customerInfo)); } - public rx.Observable> addToAccount(String customerId, String accountId, String title, String owner) { - return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(accountId, title, owner)); + public rx.Observable> addToAccount(String customerId, ToAccountInfo toAccountInfo) { + return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(toAccountInfo)); } } diff --git a/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java b/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java index 46ef41f..19ae916 100644 --- a/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java +++ b/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java @@ -2,43 +2,43 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside. import net.chrisrichardson.eventstore.CommandProcessingAggregates; import net.chrisrichardson.eventstore.Event; -import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; import org.junit.Assert; import org.junit.Test; -import java.math.BigDecimal; import java.util.List; public class CustomerTest { - @Test - public void testSomething() { - Customer customer = new Customer(); + @Test + public void testSomething() { + Customer customer = new Customer(); - CustomerInfo customerInfo = generateCustomerInfo(); + CustomerInfo customerInfo = generateCustomerInfo(); - List events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand("John", "Doe", customerInfo)); + List events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand(customerInfo)); - Assert.assertEquals(1, events.size()); - Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass()); + Assert.assertEquals(1, events.size()); + Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass()); - customer.applyEvent(events.get(0)); - Assert.assertEquals(customerInfo, customer.getCustomerInfo()); - } + customer.applyEvent(events.get(0)); + Assert.assertEquals(customerInfo, customer.getCustomerInfo()); + } - private CustomerInfo generateCustomerInfo() { - return new CustomerInfo( - "current@email.com", - "000-00-0000", - "1-111-111-1111", - new Address("street 1", - "street 2", - "City", - "State", - "1111111") - ); - } + private CustomerInfo generateCustomerInfo() { + return new CustomerInfo( + new Name("John", "Doe"), + "current@email.com", + "000-00-0000", + "1-111-111-1111", + new Address("street 1", + "street 2", + "City", + "State", + "1111111") + ); + } } diff --git a/java-spring/customers-command-side-service/build.gradle b/java-spring/customers-command-side-service/build.gradle index 034e4f7..cf208cd 100644 --- a/java-spring/customers-command-side-service/build.gradle +++ b/java-spring/customers-command-side-service/build.gradle @@ -15,6 +15,8 @@ dependencies { testCompile "org.springframework.boot:spring-boot-starter-test" } -test { - ignoreFailures true +run { + environment 'EVENTUATE_API_KEY_ID', '20CAXGPA3DE56WXO2SFBUDGZ9' + environment 'EVENTUATE_API_KEY_SECRET', 'gU6n78drWCIgkgzVStvI3BhV3MfzDyjWKCN7p0PBimI' + environment 'SPRING_DATA_MONGODB_URI', 'mongodb://198.50.218.51/mydb' } diff --git a/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceIntegrationTest.java b/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceIntegrationTest.java index 3f42c87..5f6062a 100644 --- a/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceIntegrationTest.java +++ b/java-spring/customers-command-side-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceIntegrationTest.java @@ -3,7 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; -import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CreateCustomerRequest; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -21,39 +21,40 @@ import org.springframework.web.client.RestTemplate; @IntegrationTest({"server.port=0", "management.port=0"}) public class CustomersCommandSideServiceIntegrationTest { - @Value("${local.server.port}") - private int port; + @Value("${local.server.port}") + private int port; - private String baseUrl(String path) { - return "http://localhost:" + port + "/" + path; - } + private String baseUrl(String path) { + return "http://localhost:" + port + "/" + path; + } - @Autowired - RestTemplate restTemplate; + @Autowired + RestTemplate restTemplate; - @Test - public void shouldCreateCustomer() { - CustomerInfo customerInfo = generateCustomerInfo(); + @Test + public void shouldCreateCustomer() { + CustomerInfo customerInfo = generateCustomerInfo(); - final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"),new CreateCustomerRequest("John", "Doe", customerInfo), CustomerResponse.class).getBody(); - final String customerId = customerResponse.getId(); + final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); - Assert.assertNotNull(customerId); - Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); - } + Assert.assertNotNull(customerId); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + } - private CustomerInfo generateCustomerInfo() { - return new CustomerInfo( - "current@email.com", - "000-00-0000", - "1-111-111-1111", - new Address("street 1", - "street 2", - "City", - "State", - "1111111") - ); - } + private CustomerInfo generateCustomerInfo() { + return new CustomerInfo( + new Name("John", "Doe"), + "current@email.com", + "000-00-0000", + "1-111-111-1111", + new Address("street 1", + "street 2", + "City", + "State", + "1111111") + ); + } } diff --git a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CreateCustomerRequest.java b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CreateCustomerRequest.java deleted file mode 100644 index 5657d1c..0000000 --- a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CreateCustomerRequest.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers; - -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; - -import javax.validation.constraints.NotNull; - -/** - * Created by Main on 09.02.2016. - */ -public class CreateCustomerRequest { - @NotNull - private String firstName; - @NotNull - private String lastName; - private CustomerInfo customerInfo; - - public CreateCustomerRequest() { - } - - public CreateCustomerRequest(String firstName, String lastName, CustomerInfo customerInfo) { - this.firstName = firstName; - this.lastName = lastName; - this.customerInfo = customerInfo; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public CustomerInfo getCustomerInfo() { - return customerInfo; - } - - public void setCustomerInfo(CustomerInfo customerInfo) { - this.customerInfo = customerInfo; - } -} diff --git a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java index 78086ca..5590f29 100644 --- a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java +++ b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java @@ -1,7 +1,9 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerService; +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.ToAccountInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -12,7 +14,7 @@ import rx.Observable; * Created by popikyardo on 03.02.16. */ @RestController -@RequestMapping("/customer") +@RequestMapping("/customers") public class CustomerController { private CustomerService customerService; @@ -23,14 +25,14 @@ public class CustomerController { } @RequestMapping(method = RequestMethod.POST) - public Observable createCustomer(@Validated @RequestBody CreateCustomerRequest request) { - return customerService.createCustomer(request.getFirstName(), request.getLastName(), request.getCustomerInfo()) - .map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request.getCustomerInfo())); + public Observable createCustomer(@Validated @RequestBody CustomerInfo request) { + return customerService.createCustomer(request) + .map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), request)); } @RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST) - public Observable> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountsRequest request) { - return customerService.addToAccount(id, request.getId(), request.getTitle(), request.getOwner()) + public Observable> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) { + return customerService.addToAccount(id, request) .map(entityAndEventInfo -> ResponseEntity.ok().build()); } diff --git a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/ToAccountsRequest.java b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/ToAccountsRequest.java deleted file mode 100644 index 1c218f3..0000000 --- a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/ToAccountsRequest.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers; - -/** - * Created by Main on 08.02.2016. - */ -public class ToAccountsRequest { - private String id; - private String title; - private String owner; - - public ToAccountsRequest() { - } - - public ToAccountsRequest(String id, String title, String owner) { - this.id = id; - this.title = title; - this.owner = owner; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } -} diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java index 267910b..1de7c77 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.mongodb.core.MongoTemplate; @@ -26,11 +27,10 @@ public class CustomerInfoUpdateService { this.mongoTemplate = mongoTemplate; } - public void create(String id, String firstName, String lastName, CustomerInfo customerInfo) { + public void create(String id, CustomerInfo customerInfo) { try { accountInfoRepository.save(new QuerySideCustomer(id, - firstName, - lastName, + customerInfo.getName(), customerInfo.getEmail(), customerInfo.getSsn(), customerInfo.getPhoneNumber(), diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java index c1f62ca..800f19b 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java @@ -2,6 +2,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.cu import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerAddedToAccount; import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler; import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent; import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod; @@ -13,7 +14,7 @@ import rx.Observable; /** * Created by Main on 04.02.2016. */ -@EventSubscriber(id="querySideEventHandlers") +@EventSubscriber(id = "querySideEventHandlers") public class CustomerQueryWorkflow implements CompoundEventHandler { private Logger logger = LoggerFactory.getLogger(getClass()); @@ -30,17 +31,16 @@ public class CustomerQueryWorkflow implements CompoundEventHandler { CustomerCreatedEvent event = de.event(); String id = de.getEntityIdentifier().getId(); - customerInfoUpdateService.create(id, event.getFirstName(), event.getLastName(), event.getCustomerInfo()); + customerInfoUpdateService.create(id, event.getCustomerInfo()); return Observable.just(null); } + @EventHandlerMethod public Observable addToAccount(DispatchedEvent de) { CustomerAddedToAccount event = de.event(); String id = de.getEntityIdentifier().getId(); - ToAccountInfo toAccountInfo = new ToAccountInfo(event.getAccountId(), - event.getTitle(), - event.getAccountOwner()); + ToAccountInfo toAccountInfo = event.getToAccountInfo(); customerInfoUpdateService.addToAccount(id, toAccountInfo); return Observable.just(null); diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java index 8bffb20..6dd8dc2 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java @@ -2,6 +2,8 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.cu import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; import java.util.List; @@ -10,15 +12,11 @@ import java.util.List; */ public class QuerySideCustomer extends CustomerInfo { private String id; - protected String firstName; - protected String lastName; private List toAccounts; - public QuerySideCustomer(String id, String firstName, String lastName, String email, String ssn, String phoneNumber, Address address, List toAccounts) { - super(email, ssn, phoneNumber, address); + public QuerySideCustomer(String id, Name name, String email, String ssn, String phoneNumber, Address address, List toAccounts) { + super(name, email, ssn, phoneNumber, address); this.id = id; - this.firstName = firstName; - this.lastName = lastName; this.toAccounts = toAccounts; } @@ -26,14 +24,6 @@ public class QuerySideCustomer extends CustomerInfo { return id; } - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - public List getToAccounts() { return toAccounts; } diff --git a/java-spring/customers-query-side-service/build.gradle b/java-spring/customers-query-side-service/build.gradle index 164f5ac..56fcd4a 100644 --- a/java-spring/customers-query-side-service/build.gradle +++ b/java-spring/customers-query-side-service/build.gradle @@ -13,9 +13,15 @@ dependencies { compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion" testCompile project(":testutil") + testCompile project(":customers-command-side-service") testCompile "org.springframework.boot:spring-boot-starter-test" } test { ignoreFailures true + + environment 'EVENTUATE_API_KEY_ID', '20CAXGPA3DE56WXO2SFBUDGZ9' + environment 'EVENTUATE_API_KEY_SECRET', 'gU6n78drWCIgkgzVStvI3BhV3MfzDyjWKCN7p0PBimI' + environment 'SPRING_DATA_MONGODB_URI', 'mongodb://198.50.218.51/mydb' } + 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 302d739..b92b13a 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 @@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; 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.Name; import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; import org.junit.Assert; @@ -17,8 +18,6 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import rx.Observable; -import java.math.BigDecimal; - import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; @RunWith(SpringJUnit4ClassRunner.class) @@ -68,6 +67,7 @@ public class CustomersQuerySideServiceIntegrationTest { private CustomerInfo generateCustomerInfo() { return new CustomerInfo( + new Name("John", "Doe"), "current@email.com", "000-00-0000", "1-111-111-1111", 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 f040e32..021d692 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 @@ -12,7 +12,7 @@ import java.util.Arrays; import java.util.List; @Configuration -@Import(CustomersQuerySideServiceConfiguration.class) +@Import({CustomersQuerySideServiceConfiguration.class, CustomersCommandSideServiceConfiguration.class}) public class CustomersQuerySideServiceTestConfiguration { @Bean diff --git a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java index 5035759..7e3f1b6 100644 --- a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java +++ b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java @@ -1,11 +1,10 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.customers; import net.chrisrichardson.eventstore.EntityIdentifier; -import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomer; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerNotFoundException; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerQueryService; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomersNotFoundException; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomer; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -28,35 +27,32 @@ public class CustomerQueryController { this.customerQueryService = customerQueryService; } - @RequestMapping(value="/customers/{customerId}", method = RequestMethod.GET) + @RequestMapping(value = "/customers/{customerId}", method = RequestMethod.GET) public Observable getCustomer(@PathVariable String customerId) { return customerQueryService.findByCustomerId(new EntityIdentifier(customerId)) .map(this::getCustomerResponse); } - @RequestMapping(value="/customers", method = RequestMethod.GET) + @RequestMapping(value = "/customers", method = RequestMethod.GET) public Observable getCustomersByEmail(@RequestParam String email) { return customerQueryService.findByEmail(email) .map(this::getCustomersQueryResponse); } - @ResponseStatus(value= HttpStatus.NOT_FOUND, reason="customer not found") + @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "customer not found") @ExceptionHandler(CustomerNotFoundException.class) public void customerNotFound() { } - @ResponseStatus(value= HttpStatus.NOT_FOUND, reason="customers not found") + @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "customers not found") @ExceptionHandler(CustomersNotFoundException.class) public void customersNotFound() { } private CustomerResponse getCustomerResponse(QuerySideCustomer querySideCustomer) { - return new CustomerResponse(querySideCustomer.getId(), new CustomerInfo(querySideCustomer.getEmail(), - querySideCustomer.getSsn(), - querySideCustomer.getPhoneNumber(), - querySideCustomer.getAddress())); + return new CustomerResponse(querySideCustomer.getId(), querySideCustomer); } private CustomersQueryResponse getCustomersQueryResponse(List customersList) { 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 21fbe85..7dc39db 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 @@ -47,7 +47,7 @@ public class TestUtil { public static void eventually(final Producer producer, final Verifier verifier) { final int n = 50; - Object possibleException = Observable.timer(0, 100, TimeUnit.MILLISECONDS).flatMap(new Func1>>() { + Object possibleException = Observable.timer(0, 200, TimeUnit.MILLISECONDS).flatMap(new Func1>>() { @Override public Observable> call(Long aLong) {