- simplified customers tests
- code clearings
This commit is contained in:
@@ -7,7 +7,7 @@ dependencies {
|
||||
testCompile project(":accounts-query-side-backend")
|
||||
testCompile project(":customers-command-side-backend")
|
||||
testCompile project(":customers-query-side-backend")
|
||||
testCompile project(":testutil")
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
|
||||
@@ -4,7 +4,6 @@ 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.*;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
@@ -19,6 +18,8 @@ import rx.Observable;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by Main on 10.02.2016.
|
||||
@@ -61,28 +62,10 @@ public class CustomerQuerySideIntegrationTest {
|
||||
Assert.assertEquals(customerInfo.getPhoneNumber(), querySideCustomer.getPhoneNumber());
|
||||
Assert.assertEquals(customerInfo.getAddress(), querySideCustomer.getAddress());
|
||||
|
||||
/* Assert.assertNotNull(querySideCustomer.getToAccounts());
|
||||
Assert.assertNotNull(querySideCustomer.getToAccounts());
|
||||
Assert.assertFalse(querySideCustomer.getToAccounts().isEmpty());
|
||||
Assert.assertEquals(querySideCustomer.getToAccounts().get("11111111-11111111"), toAccountInfo);*/
|
||||
Assert.assertEquals(querySideCustomer.getToAccounts().get("11111111-11111111"), toAccountInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
|
||||
private ToAccountInfo generateToAccountInfo() {
|
||||
return new ToAccountInfo("11111111-11111111", "New Account", "John Doe");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ dependencies {
|
||||
compile project(":common-backend")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
|
||||
@@ -3,14 +3,14 @@ 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.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.util.List;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
public class CustomerTest {
|
||||
|
||||
@Test
|
||||
@@ -27,18 +27,4 @@ public class CustomerTest {
|
||||
customer.applyEvent(events.get(0));
|
||||
Assert.assertEquals(customerInfo, customer.getCustomerInfo());
|
||||
}
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ dependencies {
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
}
|
||||
@@ -1,9 +1,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 org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -15,6 +13,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = CustomersCommandSideServiceTestConfiguration.class)
|
||||
@WebAppConfiguration
|
||||
@@ -43,18 +43,4 @@ public class CustomersCommandSideServiceIntegrationTest {
|
||||
Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo());
|
||||
}
|
||||
|
||||
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,5 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -12,7 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@Import(CustomersCommandSideServiceConfiguration.class)
|
||||
@Import({CustomersCommandSideServiceConfiguration.class, AuthConfiguration.class})
|
||||
public class CustomersCommandSideServiceTestConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -12,7 +12,7 @@ dependencies {
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile project(":customers-command-side-service")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*;
|
||||
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.junit.runner.RunWith;
|
||||
@@ -15,7 +16,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = CustomersQuerySideServiceTestConfiguration.class)
|
||||
@@ -33,51 +37,23 @@ public class CustomersQuerySideServiceIntegrationTest {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldGetCustomerById() {
|
||||
|
||||
CustomerInfo customerInfo = generateCustomerInfo();
|
||||
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"),customerInfo, CustomerResponse.class).getBody();
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody();
|
||||
final String customerId = customerResponse.getId();
|
||||
|
||||
assertCustomerResponse(customerId, customerInfo);
|
||||
}
|
||||
|
||||
private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(restTemplate.getForEntity(baseUrl("/customers/" + customerId), QuerySideCustomer.class).getBody());
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@Override
|
||||
public void verify(QuerySideCustomer customerResponse) {
|
||||
Assert.assertEquals(customerId, customerResponse.getId());
|
||||
Assert.assertEquals(customerInfo.getName(), customerResponse.getName());
|
||||
Assert.assertEquals(customerInfo.getEmail(), customerResponse.getEmail());
|
||||
Assert.assertEquals(customerInfo.getPhoneNumber(), customerResponse.getPhoneNumber());
|
||||
Assert.assertEquals(customerInfo.getSsn(), customerResponse.getSsn());
|
||||
Assert.assertEquals(customerInfo.getAddress(), customerResponse.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")
|
||||
);
|
||||
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -12,7 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@Import({CustomersQuerySideServiceConfiguration.class, CustomersQuerySideServiceConfiguration.class})
|
||||
@Import({CustomersQuerySideServiceConfiguration.class, CustomersQuerySideServiceConfiguration.class, AuthConfiguration.class})
|
||||
public class CustomersQuerySideServiceTestConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -7,7 +7,7 @@ dependencies {
|
||||
testCompile project(":transactions-command-side-web")
|
||||
testCompile project(":accounts-query-side-web")
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile project(":common-auth")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.examples.bank.web;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*;
|
||||
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;
|
||||
@@ -11,6 +12,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.account
|
||||
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
|
||||
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.http.HttpMethod;
|
||||
@@ -22,6 +24,7 @@ import rx.Observable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
public class EndToEndTest {
|
||||
|
||||
@@ -53,6 +56,8 @@ public class EndToEndTest {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
{
|
||||
|
||||
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
|
||||
@@ -60,6 +65,8 @@ public class EndToEndTest {
|
||||
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(EventStoreCommonObjectMapping.getObjectMapper());
|
||||
}
|
||||
}
|
||||
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, customersQuerySideBaseUrl("/customers/"));
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +84,7 @@ public class EndToEndTest {
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(customersCommandSideBaseUrl("/customers"),customerInfo, CustomerResponse.class).getBody();
|
||||
final String customerId = customerResponse.getId();
|
||||
|
||||
assertCustomerResponse(customerId, customerInfo);
|
||||
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
|
||||
|
||||
|
||||
final CreateAccountResponse fromAccount = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
@@ -142,45 +149,4 @@ public class EndToEndTest {
|
||||
});
|
||||
}
|
||||
|
||||
private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
customersQuerySideBaseUrl("/customers/" + customerId),
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@Override
|
||||
public void verify(QuerySideCustomer querySideCustomer) {
|
||||
Assert.assertEquals(customerId, querySideCustomer.getId());
|
||||
assertQuerySideCustomerEqualscCustomerInfo(querySideCustomer, customerInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
|
||||
private void assertQuerySideCustomerEqualscCustomerInfo(QuerySideCustomer querySideCustomer, CustomerInfo customerInfo) {
|
||||
Assert.assertEquals(querySideCustomer.getName(), customerInfo.getName());
|
||||
Assert.assertEquals(querySideCustomer.getEmail(), customerInfo.getEmail());
|
||||
Assert.assertEquals(querySideCustomer.getPhoneNumber(), customerInfo.getPhoneNumber());
|
||||
Assert.assertEquals(querySideCustomer.getSsn(), customerInfo.getSsn());
|
||||
Assert.assertEquals(querySideCustomer.getAddress(), customerInfo.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ dependencies {
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthRequest;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils;
|
||||
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.junit.runner.RunWith;
|
||||
@@ -12,13 +12,13 @@ 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.http.HttpMethod;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
/**
|
||||
* Created by Main on 15.02.2016.
|
||||
@@ -35,6 +35,13 @@ public class BankingAuthTest {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
|
||||
}
|
||||
|
||||
private String baseUrl(String path) {
|
||||
return "http://localhost:" + port + "/" + path;
|
||||
}
|
||||
@@ -50,58 +57,17 @@ public class BankingAuthTest {
|
||||
Assert.assertNotNull(customerId);
|
||||
Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo());
|
||||
|
||||
assertCustomerResponse(customerId, customerInfo);
|
||||
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
|
||||
|
||||
AuthRequest authRequest = new AuthRequest(email);
|
||||
|
||||
final QuerySideCustomer loginQuerySideCustomer = restTemplate.postForEntity(baseUrl("/login"), authRequest, QuerySideCustomer.class).getBody();
|
||||
|
||||
assertQuerySideCustomerEqualscCustomerInfo(loginQuerySideCustomer, customerResponse.getCustomerInfo());
|
||||
customersTestUtils.assertQuerySideCustomerEqualscCustomerInfo(loginQuerySideCustomer, customerResponse.getCustomerInfo());
|
||||
}
|
||||
|
||||
private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/customers/" + customerId),
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@Override
|
||||
public void verify(QuerySideCustomer querySideCustomer) {
|
||||
Assert.assertEquals(customerId, querySideCustomer.getId());
|
||||
assertQuerySideCustomerEqualscCustomerInfo(querySideCustomer, customerInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private CustomerInfo generateCustomerInfo(String email) {
|
||||
return new CustomerInfo(
|
||||
new Name("John", "Doe"),
|
||||
email,
|
||||
"000-00-0000",
|
||||
"1-111-111-1111",
|
||||
new Address("street 1",
|
||||
"street 2",
|
||||
"City",
|
||||
"State",
|
||||
"1111111")
|
||||
);
|
||||
}
|
||||
|
||||
private String uniqueEmail() {
|
||||
return System.currentTimeMillis() + "@email.com";
|
||||
}
|
||||
|
||||
private void assertQuerySideCustomerEqualscCustomerInfo(QuerySideCustomer querySideCustomer, CustomerInfo customerInfo) {
|
||||
Assert.assertEquals(querySideCustomer.getName(), customerInfo.getName());
|
||||
Assert.assertEquals(querySideCustomer.getEmail(), customerInfo.getEmail());
|
||||
Assert.assertEquals(querySideCustomer.getPhoneNumber(), customerInfo.getPhoneNumber());
|
||||
Assert.assertEquals(querySideCustomer.getSsn(), customerInfo.getSsn());
|
||||
Assert.assertEquals(querySideCustomer.getAddress(), customerInfo.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.trans
|
||||
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.junit.runner.RunWith;
|
||||
@@ -22,9 +23,12 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
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;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class)
|
||||
@@ -42,6 +46,13 @@ public class BankingWebIntegrationTest {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldCreateAccountsAndTransferMoney() {
|
||||
@@ -98,7 +109,7 @@ public class BankingWebIntegrationTest {
|
||||
Assert.assertNotNull(customerId);
|
||||
Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo());
|
||||
|
||||
//assertCustomerResponse(customerId, customerInfo);
|
||||
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
|
||||
|
||||
ToAccountInfo toAccountInfo = generateToAccountInfo();
|
||||
|
||||
@@ -137,30 +148,6 @@ public class BankingWebIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/customers/" + customerId),
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@Override
|
||||
public void verify(QuerySideCustomer customerResponse) {
|
||||
Assert.assertEquals(customerId, customerResponse.getId());
|
||||
Assert.assertEquals(customerInfo.getName(), customerResponse.getName());
|
||||
Assert.assertEquals(customerInfo.getEmail(), customerResponse.getEmail());
|
||||
Assert.assertEquals(customerInfo.getPhoneNumber(), customerResponse.getPhoneNumber());
|
||||
Assert.assertEquals(customerInfo.getSsn(), customerResponse.getSsn());
|
||||
Assert.assertEquals(customerInfo.getAddress(), customerResponse.getAddress());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertToAccountsContains(final String customerId, final ToAccountInfo toAccountInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@@ -181,23 +168,4 @@ public class BankingWebIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
|
||||
private ToAccountInfo generateToAccountInfo() {
|
||||
return new ToAccountInfo("11111111-11111111", "New Account", "John Doe");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,4 +34,5 @@ include 'customers-command-side-service'
|
||||
include 'customers-query-side-service'
|
||||
include 'common-auth-web'
|
||||
include 'api-gateway-service'
|
||||
include 'testutil-customers'
|
||||
|
||||
|
||||
8
java-spring/testutil-customers/build.gradle
Normal file
8
java-spring/testutil-customers/build.gradle
Normal file
@@ -0,0 +1,8 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile project(":testutil")
|
||||
compile project(":common-auth")
|
||||
compile project(":common-customers")
|
||||
compile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.utils.BasicAuthUtils;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 02.03.16.
|
||||
*/
|
||||
public class CustomersTestUtils {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private String customersBaseUrl;
|
||||
|
||||
public CustomersTestUtils(RestTemplate restTemplate, String customersBaseUrl) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.customersBaseUrl = customersBaseUrl;
|
||||
}
|
||||
|
||||
public void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
customersBaseUrl + customerId,
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
@Override
|
||||
public void verify(QuerySideCustomer querySideCustomer) {
|
||||
Assert.assertEquals(customerId, querySideCustomer.getId());
|
||||
assertQuerySideCustomerEqualscCustomerInfo(querySideCustomer, customerInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void assertQuerySideCustomerEqualscCustomerInfo(QuerySideCustomer querySideCustomer, CustomerInfo customerInfo) {
|
||||
Assert.assertEquals(querySideCustomer.getName(), customerInfo.getName());
|
||||
Assert.assertEquals(querySideCustomer.getEmail(), customerInfo.getEmail());
|
||||
Assert.assertEquals(querySideCustomer.getPhoneNumber(), customerInfo.getPhoneNumber());
|
||||
Assert.assertEquals(querySideCustomer.getSsn(), customerInfo.getSsn());
|
||||
Assert.assertEquals(querySideCustomer.getAddress(), customerInfo.getAddress());
|
||||
}
|
||||
|
||||
public static CustomerInfo generateCustomerInfo() {
|
||||
return generateCustomerInfo("current@email.com");
|
||||
}
|
||||
|
||||
public static CustomerInfo generateCustomerInfo(String email) {
|
||||
return new CustomerInfo(
|
||||
new Name("John", "Doe"),
|
||||
email,
|
||||
"000-00-0000",
|
||||
"1-111-111-1111",
|
||||
new Address("street 1",
|
||||
"street 2",
|
||||
"City",
|
||||
"State",
|
||||
"1111111")
|
||||
);
|
||||
}
|
||||
|
||||
public static ToAccountInfo generateToAccountInfo() {
|
||||
return new ToAccountInfo("11111111-11111111", "New Account", "John Doe");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user