refactoring
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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> customer = await(customerService.createCustomer(customerInfo));
|
||||
|
||||
Thread.sleep(10000);
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return customerQueryService.findByCustomerId(customer.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@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")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.common.customers;
|
||||
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Custom
|
||||
|
||||
private CustomerInfo customerInfo;
|
||||
|
||||
|
||||
public List<Event> process(CreateCustomerCommand cmd) {
|
||||
return EventUtil.events(new CustomerCreatedEvent(cmd.getFirstName(), cmd.getLastName(), cmd.getCustomerInfo()));
|
||||
return EventUtil.events(new CustomerCreatedEvent(cmd.getCustomerInfo()));
|
||||
}
|
||||
|
||||
public List<Event> 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;
|
||||
}
|
||||
|
||||
@@ -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<EntityWithIdAndVersion<Customer>> createCustomer(String firstName, String lastName, CustomerInfo customerInfo) {
|
||||
return accountRepository.save(new CreateCustomerCommand(firstName, lastName, customerInfo));
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> createCustomer(CustomerInfo customerInfo) {
|
||||
return accountRepository.save(new CreateCustomerCommand(customerInfo));
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, String accountId, String title, String owner) {
|
||||
return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(accountId, title, owner));
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, ToAccountInfo toAccountInfo) {
|
||||
return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(toAccountInfo));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Event> events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand("John", "Doe", customerInfo));
|
||||
List<Event> 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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<CustomerResponse> 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<CustomerResponse> 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<ResponseEntity<?>> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountsRequest request) {
|
||||
return customerService.addToAccount(id, request.getId(), request.getTitle(), request.getOwner())
|
||||
public Observable<ResponseEntity<?>> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) {
|
||||
return customerService.addToAccount(id, request)
|
||||
.map(entityAndEventInfo -> ResponseEntity.ok().build());
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
@@ -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<Object> addToAccount(DispatchedEvent<CustomerAddedToAccount> 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);
|
||||
|
||||
@@ -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<ToAccountInfo> toAccounts;
|
||||
|
||||
public QuerySideCustomer(String id, String firstName, String lastName, String email, String ssn, String phoneNumber, Address address, List<ToAccountInfo> toAccounts) {
|
||||
super(email, ssn, phoneNumber, address);
|
||||
public QuerySideCustomer(String id, Name name, String email, String ssn, String phoneNumber, Address address, List<ToAccountInfo> 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<ToAccountInfo> getToAccounts() {
|
||||
return toAccounts;
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<CustomerResponse> 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<CustomersQueryResponse> 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<QuerySideCustomer> customersList) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TestUtil {
|
||||
|
||||
public static <T> void eventually(final Producer<T> producer, final Verifier<T> verifier) {
|
||||
final int n = 50;
|
||||
Object possibleException = Observable.timer(0, 100, TimeUnit.MILLISECONDS).flatMap(new Func1<Long, Observable<Outcome<T>>>() {
|
||||
Object possibleException = Observable.timer(0, 200, TimeUnit.MILLISECONDS).flatMap(new Func1<Long, Observable<Outcome<T>>>() {
|
||||
|
||||
@Override
|
||||
public Observable<Outcome<T>> call(Long aLong) {
|
||||
|
||||
Reference in New Issue
Block a user