Merge commit '21d21b983384188ff2f6ae985caca26e17785087' into wip-customer

* commit '21d21b983384188ff2f6ae985caca26e17785087':
  - simplified customers tests - code clearings
  - updated swagger description - added api-gateway to docker-compose build
  - added api-gateway-service - fixed ObservableReturnValueHandler
This commit is contained in:
Andrew Revinsky (DART)
2016-03-10 23:58:13 +03:00
40 changed files with 927 additions and 341 deletions

View File

@@ -0,0 +1,25 @@
apply plugin: 'java'
apply plugin: 'spring-boot'
dependencies {
compile project(":common-auth-web")
compile project(":common-web")
compile "org.apache.httpcomponents:httpclient:4.5"
compile "org.apache.httpcomponents:fluent-hc:4.5.1"
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
testCompile "junit:junit:4.11"
}
task copyWebStatic(type: Copy) {
from "../../prebuilt-web-client"
into "build/resources/main/static"
}
jar.dependsOn(copyWebStatic)

View File

@@ -0,0 +1,60 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
/**
* Created by popikyardo on 15.01.16.
*/
@ConfigurationProperties(prefix = "api.gateway")
public class ApiGatewayProperties {
private List<Endpoint> endpoints;
public static class Endpoint {
private String path;
private RequestMethod method;
private String location;
public Endpoint() {
}
public Endpoint(String location) {
this.location = location;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public RequestMethod getMethod() {
return method;
}
public void setMethod(RequestMethod method) {
this.method = method;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
public List<Endpoint> getEndpoints() {
return endpoints;
}
public void setEndpoints(List<Endpoint> endpoints) {
this.endpoints = endpoints;
}
}

View File

@@ -0,0 +1,50 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.Collections;
/**
* Created by popikyardo on 15.01.16.
*/
@Configuration
@ComponentScan
@EnableAutoConfiguration
@Import({EventStoreHttpClientConfiguration.class, AuthConfiguration.class})
@EnableConfigurationProperties({ApiGatewayProperties.class})
public class ApiGatewayServiceConfiguration extends WebMvcConfigurerAdapter {
@Bean
public RestTemplate restTemplate(HttpMessageConverters converters) {
// we have to define Apache HTTP client to use the PATCH verb
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/json"));
converter.setObjectMapper(new ObjectMapper());
HttpClient httpClient = HttpClients.createDefault();
RestTemplate restTemplate = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
restTemplate.setErrorHandler(new RestTemplateErrorHandler());
return restTemplate;
}
}

View File

@@ -0,0 +1,24 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import java.io.IOException;
public class RestTemplateErrorHandler implements ResponseErrorHandler {
private static final Logger log = LoggerFactory.getLogger(RestTemplateErrorHandler.class);
@Override
public void handleError(ClientHttpResponse response) throws IOException {
log.error("Response error: {} {}", response.getStatusCode(), response.getStatusText());
}
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return RestUtil.isError(response.getStatusCode());
}
}

View File

@@ -0,0 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway;
import org.springframework.http.HttpStatus;
/**
* Created by popikyardo on 07.12.15.
*/
public class RestUtil {
public static boolean isError(HttpStatus status) {
HttpStatus.Series series = status.series();
return (HttpStatus.Series.CLIENT_ERROR.equals(series)
|| HttpStatus.Series.SERVER_ERROR.equals(series));
}
}

View File

@@ -0,0 +1,75 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.controller;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.ApiGatewayProperties;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils.ContentRequestTransformer;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils.HeadersRequestTransformer;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils.URLRequestTransformer;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.util.stream.Collectors;
import static org.springframework.web.bind.annotation.RequestMethod.*;
/**
* Created by popikyardo on 15.01.16.
*/
@RestController
public class GatewayController {
Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private ApiGatewayProperties apiGatewayProperties;
private HttpClient httpClient;
@PostConstruct
public void init() {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
}
@RequestMapping(value = "/**", method = {GET, POST})
public String proxyRequest(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, IOException, URISyntaxException {
HttpUriRequest proxiedRequest = createHttpUriRequest(request);
log.info("request: {}", proxiedRequest);
HttpResponse proxiedResponse = httpClient.execute(proxiedRequest);
return read(proxiedResponse.getEntity().getContent());
}
private HttpUriRequest createHttpUriRequest(HttpServletRequest request) throws URISyntaxException, NoSuchRequestHandlingMethodException, IOException {
URLRequestTransformer urlRequestTransformer = new URLRequestTransformer(apiGatewayProperties);
ContentRequestTransformer contentRequestTransformer = new ContentRequestTransformer();
HeadersRequestTransformer headersRequestTransformer = new HeadersRequestTransformer();
headersRequestTransformer.setPredecessor(contentRequestTransformer);
contentRequestTransformer.setPredecessor(urlRequestTransformer);
return headersRequestTransformer.transform(request).build();
}
private String read(InputStream input) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
return buffer.lines().collect(Collectors.joining("\n"));
}
}
}

View File

@@ -0,0 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.main;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.ApiGatewayServiceConfiguration;
import org.springframework.boot.SpringApplication;
/**
* Created by Main on 19.01.2016.
*/
public class ApiGatewayServiceMain {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayServiceConfiguration.class, args);
}
}

View File

@@ -0,0 +1,30 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.stream.Collectors;
/**
* Created by popikyardo on 21.01.16.
*/
public class ContentRequestTransformer extends ProxyRequestTransformer {
@Override
public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException {
RequestBuilder requestBuilder = predecessor.transform(request);
String requestContent = request.getReader().lines().collect(Collectors.joining(""));
if(!requestContent.isEmpty()) {
StringEntity entity = new StringEntity(requestContent, ContentType.APPLICATION_JSON);
requestBuilder.setEntity(entity);
}
return requestBuilder;
}
}

View File

@@ -0,0 +1,32 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils;
import org.apache.http.client.methods.RequestBuilder;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Enumeration;
/**
* Created by popikyardo on 21.01.16.
*/
public class HeadersRequestTransformer extends ProxyRequestTransformer {
@Override
public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException {
RequestBuilder requestBuilder = predecessor.transform(request);
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
if(headerName.equals("x-access-token")) {
requestBuilder.addHeader(headerName, headerValue);
}
}
return requestBuilder;
}
}

View File

@@ -0,0 +1,22 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils;
import org.apache.http.client.methods.RequestBuilder;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* Created by popikyardo on 21.01.16.
*/
public abstract class ProxyRequestTransformer {
protected ProxyRequestTransformer predecessor;
public abstract RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException;
public void setPredecessor(ProxyRequestTransformer transformer) {
this.predecessor = transformer;
};
}

View File

@@ -0,0 +1,48 @@
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway.utils;
import net.chrisrichardson.eventstore.javaexamples.banking.apigateway.ApiGatewayProperties;
import org.apache.http.client.methods.RequestBuilder;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by popikyardo on 21.01.16.
*/
public class URLRequestTransformer extends ProxyRequestTransformer {
private ApiGatewayProperties apiGatewayProperties;
public URLRequestTransformer(ApiGatewayProperties apiGatewayProperties) {
this.apiGatewayProperties = apiGatewayProperties;
}
@Override
public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException {
String requestURI = request.getRequestURI();
URI uri;
if (request.getQueryString() != null && !request.getQueryString().isEmpty()) {
uri = new URI(getServiceUrl(requestURI, request) + "?" + request.getQueryString());
} else {
uri = new URI(getServiceUrl(requestURI, request));
}
RequestBuilder rb = RequestBuilder.create(request.getMethod());
rb.setUri(uri);
return rb;
}
private String getServiceUrl(String requestURI, HttpServletRequest httpServletRequest) throws NoSuchRequestHandlingMethodException {
ApiGatewayProperties.Endpoint endpoint =
apiGatewayProperties.getEndpoints().stream()
.filter(e ->
requestURI.matches(e.getPath()) && e.getMethod() == RequestMethod.valueOf(httpServletRequest.getMethod())
)
.findFirst().orElseThrow(() -> new NoSuchRequestHandlingMethodException(httpServletRequest));
return endpoint.getLocation() + requestURI;
}
}

View File

@@ -0,0 +1,22 @@
accounts.commandside.service.host=localhost
accounts.queryside.service.host=localhost
customers.commandside.service.host=localhost
customers.queryside.service.host=localhost
transfers.commandside.service.host=localhost
api.gateway.endpoints[0].path=[/]*accounts.*
api.gateway.endpoints[0].method=GET
api.gateway.endpoints[0].location=http://${accounts.queryside.service.host}:8080
api.gateway.endpoints[1].path=[/]*accounts.*
api.gateway.endpoints[1].method=POST
api.gateway.endpoints[1].location=http://${accounts.commandside.service.host}:8080
api.gateway.endpoints[2].path=[/]*customers.*
api.gateway.endpoints[2].method=GET
api.gateway.endpoints[2].location=http://${customers.queryside.service.host}:8080
api.gateway.endpoints[3].path=[/]*customers.*
api.gateway.endpoints[3].method=POST
api.gateway.endpoints[3].location=http://${customers.commandside.service.host}:8080
api.gateway.endpoints[4].path=[/]*transfers.*
api.gateway.endpoints[4].method=POST
api.gateway.endpoints[4].location=http://${transfers.commandside.service.host}:8080

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- [%thread] -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</Pattern>
</layout>
</appender>
<root level="error">
<appender-ref ref="STDOUT" />
</root>
<logger name="org.springframework" level='info'>
</logger>
<logger name="net.chrisrichardson.eventstore.client" level='info'>
</logger>
</configuration>

View File

@@ -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"

View File

@@ -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.
@@ -67,22 +68,4 @@ public class CustomerQuerySideIntegrationTest {
}
});
}
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");
}
}

View File

@@ -1,7 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
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.CustomerAuthService;
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthRequest;
@@ -37,12 +36,12 @@ public class AuthController {
private static ObjectMapper objectMapper = new ObjectMapper();
@RequestMapping(value = "/login", method = POST)
public ResponseEntity<CustomerResponse> doAuth(@RequestBody @Valid AuthRequest request) throws IOException {
public ResponseEntity<QuerySideCustomer> doAuth(@RequestBody @Valid AuthRequest request) throws IOException {
QuerySideCustomer customer = customerAuthService.findByEmail(request.getEmail());
Token token = tokenService.allocateToken(objectMapper.writeValueAsString(new User(request.getEmail())));
return ResponseEntity.status(HttpStatus.OK).header("access-token", token.getKey())
.body(new CustomerResponse(customer.getId(), customer));
.body(customer);
}
@ResponseStatus(value = HttpStatus.NOT_FOUND)

View File

@@ -5,13 +5,25 @@ import java.util.Map;
/**
* Created by Main on 05.02.2016.
*/
public class QuerySideCustomer extends CustomerInfo {
public class QuerySideCustomer{
private String id;
private Name name;
private String email;
private String ssn;
private String phoneNumber;
private Address address;
private Map<String, ToAccountInfo> toAccounts;
public QuerySideCustomer() {
}
public QuerySideCustomer(String id, Name name, String email, String ssn, String phoneNumber, Address address, Map<String, ToAccountInfo> toAccounts) {
super(name, email, ssn, phoneNumber, address);
this.id = id;
this.name = name;
this.email = email;
this.ssn = ssn;
this.phoneNumber = phoneNumber;
this.address = address;
this.toAccounts = toAccounts;
}
@@ -19,7 +31,55 @@ public class QuerySideCustomer extends CustomerInfo {
return id;
}
public void setId(String id) {
this.id = id;
}
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Map<String, ToAccountInfo> getToAccounts() {
return toAccounts;
}
public void setToAccounts(Map<String, ToAccountInfo> toAccounts) {
this.toAccounts = toAccounts;
}
}

View File

@@ -14,7 +14,7 @@ public class ObservableReturnValueHandler implements HandlerMethodReturnValueHan
@Override
public boolean supportsReturnType(MethodParameter returnType) {
return Observable.class.equals(returnType.getParameterType());
return Observable.class.isAssignableFrom(returnType.getParameterType());
}
@Override

View File

@@ -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"

View File

@@ -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")
);
}
}

View File

@@ -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"
}

View File

@@ -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")
);
}
}

View File

@@ -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

View File

@@ -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"
}

View File

@@ -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);
}
}

View File

@@ -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, CustomersCommandSideServiceConfiguration.class})
@Import({CustomersQuerySideServiceConfiguration.class, CustomersQuerySideServiceConfiguration.class, AuthConfiguration.class})
public class CustomersQuerySideServiceTestConfiguration {
@Bean

View File

@@ -1,8 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.customers;
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerQueryService;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -11,7 +10,6 @@ import org.springframework.web.bind.annotation.*;
import rx.Observable;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by Main on 05.02.2016.
@@ -44,10 +42,6 @@ public class CustomerQueryController {
}
private CustomerResponse getCustomerResponse(QuerySideCustomer querySideCustomer) {
return new CustomerResponse(querySideCustomer.getId(), querySideCustomer);
}
private CustomersQueryResponse getCustomersQueryResponse(List<QuerySideCustomer> customersList) {
return new CustomersQueryResponse(customersList);
}

View File

@@ -1,4 +1,4 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.customers;
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;

View File

@@ -1,4 +1,4 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside;
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomerConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;

View File

@@ -1,3 +1,21 @@
apigateway:
image: java:8
working_dir: /app
volumes:
- ./api-gateway-service/build/libs:/app
command: java -jar /app/api-gateway-service.jar --accounts.commandside.service.host=accountscommandside --transactions.commandside.service.host=transactionscommandside --accounts.queryside.service.host=accountsqueryside --customers.commandside.service.host=customerscommandside --customers.queryside.service.host=customersqueryside
ports:
- "8080:8080"
links:
- accountscommandside
- transactionscommandside
- accountsqueryside
- customerscommandside
- customersqueryside
environment:
EVENTUATE_API_KEY_ID:
EVENTUATE_API_KEY_SECRET:
accountscommandside:
image: java:8
working_dir: /app
@@ -5,7 +23,7 @@ accountscommandside:
- ./accounts-command-side-service/build/libs:/app
command: java -jar /app/accounts-command-side-service.jar
ports:
- "8080:8080"
- "8085:8080"
environment:
EVENTUATE_API_KEY_ID:
EVENTUATE_API_KEY_SECRET:

View File

@@ -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"

View File

@@ -1,10 +1,8 @@
package net.chrisrichardson.eventstore.examples.bank.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.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;
@@ -14,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;
@@ -25,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 {
@@ -56,6 +56,8 @@ public class EndToEndTest {
RestTemplate restTemplate = new RestTemplate();
CustomersTestUtils customersTestUtils;
{
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
@@ -63,6 +65,8 @@ public class EndToEndTest {
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(EventStoreCommonObjectMapping.getObjectMapper());
}
}
customersTestUtils = new CustomersTestUtils(restTemplate, customersQuerySideBaseUrl("/customers/"));
}
@@ -80,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,
@@ -145,38 +149,4 @@ public class EndToEndTest {
});
}
private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) {
eventually(
new Producer<CustomerResponse>() {
@Override
public Observable<CustomerResponse> produce() {
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
customersQuerySideBaseUrl("/customers/" + customerId),
HttpMethod.GET,
CustomerResponse.class));
}
},
new Verifier<CustomerResponse>() {
@Override
public void verify(CustomerResponse customerResponse) {
Assert.assertEquals(customerId, customerResponse.getId());
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")
);
}
}

View File

@@ -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"
}

View File

@@ -5,7 +5,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonS
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CustomersCommandSideWebConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.CustomersQuerySideWebConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside.CustomersQuerySideWebConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

View File

@@ -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,52 +57,15 @@ public class BankingAuthTest {
Assert.assertNotNull(customerId);
Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo());
assertCustomerResponse(customerId, customerInfo);
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
AuthRequest authRequest = new AuthRequest(email);
final CustomerResponse loginCustomerResponse = restTemplate.postForEntity(baseUrl("/login"), authRequest, CustomerResponse.class).getBody();
final QuerySideCustomer loginQuerySideCustomer = restTemplate.postForEntity(baseUrl("/login"), authRequest, QuerySideCustomer.class).getBody();
Assert.assertEquals(customerResponse, loginCustomerResponse);
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 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(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";

View File

@@ -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();
@@ -109,7 +120,7 @@ public class BankingWebIntegrationTest {
toAccountInfo
);
//assertToAccountsContains(customerId, toAccountInfo);
assertToAccountsContains(customerId, toAccountInfo);
}
private BigDecimal toCents(BigDecimal dollarAmount) {
@@ -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");
}
}

View File

@@ -17,30 +17,38 @@
"basePath": "/",
"tags": [
{
"name": "customer-service-command-side-controller",
"description": "Customer Service Commandside Controller"
"name": "account-query-controller",
"description": "Account Query Controller"
},
{
"name": "customer-service-query-side-controller",
"description": "Customer Service Queryside Controller"
},
{
"name": "account-query-side-controller",
"description": "Account Service Queryside Controller"
"name": "money-transfer-controller",
"description": "Money Transfer Controller"
},
{
"name": "auth-controller",
"description": "Authentication Controller"
"description": "Auth Controller"
},
{
"name": "customer-controller",
"description": "Customer Controller"
},
{
"name": "customer-query-controller",
"description": "Customer Query Controller"
},
{
"name": "account-controller",
"description": "Account Controller"
}
],
"paths": {
"/login": {
"/accounts": {
"post": {
"tags": [
"auth-controller"
"account-controller"
],
"summary": "doAuth",
"operationId": "doAuthUsingPOST",
"summary": "createAccount",
"operationId": "createAccountUsingPOST",
"consumes": [
"application/json"
],
@@ -54,7 +62,7 @@
"description": "request",
"required": true,
"schema": {
"$ref": "#/definitions/AuthRequest"
"$ref": "#/definitions/CreateAccountRequest"
}
}
],
@@ -62,7 +70,39 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/CustomerResponse"
"$ref": "#/definitions/CreateAccountResponse"
}
}
}
}
},
"/accounts/{accountId}": {
"get": {
"tags": [
"account-query-controller"
],
"summary": "get",
"operationId": "getUsingGET",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "accountId",
"in": "path",
"description": "accountId",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/GetAccountResponse"
}
}
}
@@ -71,21 +111,21 @@
"/customers": {
"get": {
"tags": [
"customer-service-query-side-controller"
"customer-query-controller"
],
"summary": "getAllCustomersByEmail",
"operationId": "getAllCustomersByEmailUsingGET",
"summary": "getCustomersByEmail",
"operationId": "getCustomersByEmailUsingGET",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
"parameters": [
{
"name": "email",
"in": "query",
"description": "customer's email",
"description": "email",
"required": true,
"type": "string"
}
@@ -101,10 +141,10 @@
},
"post": {
"tags": [
"customer-service-command-side-controller"
"customer-controller"
],
"summary": "saveCustomer",
"operationId": "saveCustomerUsingPOST",
"summary": "createCustomer",
"operationId": "createCustomerUsingPOST",
"consumes": [
"application/json"
],
@@ -128,20 +168,17 @@
"schema": {
"$ref": "#/definitions/CustomerResponse"
}
},
"400": {
"description": "Validation error"
}
}
}
},
"/customers/{id}": {
"/customers/{customerId}": {
"get": {
"tags": [
"customer-service-query-side-controller"
"customer-query-controller"
],
"summary": "getBoard",
"operationId": "getBoardUsingGET",
"summary": "getCustomer",
"operationId": "getCustomerUsingGET",
"consumes": [
"application/json"
],
@@ -150,9 +187,9 @@
],
"parameters": [
{
"name": "id",
"name": "customerId",
"in": "path",
"description": "id",
"description": "customerId",
"required": true,
"type": "string"
}
@@ -161,7 +198,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/CustomerResponse"
"$ref": "#/definitions/QuerySideCustomer"
}
}
}
@@ -170,7 +207,7 @@
"/customers/{id}/toaccounts": {
"post": {
"tags": [
"customer-service-command-side-controller"
"customer-controller"
],
"summary": "addToAccount",
"operationId": "addToAccountUsingPOST",
@@ -200,94 +237,166 @@
],
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Validation error"
"description": "OK",
"schema": {
"type": "string"
}
}
}
}
},
"/login": {
"post": {
"tags": [
"auth-controller"
],
"summary": "doAuth",
"operationId": "doAuthUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "request",
"description": "request",
"required": true,
"schema": {
"$ref": "#/definitions/AuthRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/QuerySideCustomer"
}
}
}
}
},
"/transfers": {
"post": {
"tags": [
"money-transfer-controller"
],
"summary": "createMoneyTransfer",
"operationId": "createMoneyTransferUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "request",
"description": "request",
"required": true,
"schema": {
"$ref": "#/definitions/CreateMoneyTransferRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/CreateMoneyTransferResponse"
}
}
}
}
}
},
"definitions": {
"CreateAccountResponse": {
"properties": {
"accountId": {
"type": "string"
}
}
},
"AuthRequest": {
"required": [ "email" ],
"properties": {
"email": {
"type": "string"
}
}
},
"AuthResponse": {
"QuerySideCustomer": {
"properties": {
"token": {
"address": {
"$ref": "#/definitions/Address"
},
"email": {
"type": "string"
}
}
},
"CustomerInfo": {
"required": [ "email" ],
"properties": {
},
"id": {
"type": "string"
},
"name": {
"$ref": "#/definitions/Name"
},
"email": {
"phoneNumber": {
"type": "string"
},
"ssn": {
"type": "string"
},
"phoneNumber": {
"type": "string"
},
"address": {
"$ref": "#/definitions/Address"
}
}
},
"CustomersQueryResponse": {
"properties": {
"customers": {
"type": "array",
"items": {
"$ref": "#/definitions/CustomerResponse"
"toAccounts": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/ToAccountInfo"
}
}
}
},
"CustomerResponse": {
"required": [ "id", "customerInfo" ],
"Address": {
"properties": {
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"street1": {
"type": "string"
},
"street2": {
"type": "string"
},
"zipCode": {
"type": "string"
}
}
},
"CreateMoneyTransferResponse": {
"properties": {
"moneyTransferId": {
"type": "string"
}
}
},
"ToAccountInfo": {
"properties": {
"id": {
"type": "string"
},
"customerInfo": {
"$ref": "#/definitions/CustomerInfo"
}
}
},
"AccountsQueryResponse": {
"properties": {
"customers": {
"type": "array",
"items": {
"$ref": "#/definitions/GetAccountResponse"
}
}
}
},
"GetAccountResponse": {
"properties": {
"accountId": {
"owner": {
"type": "string"
},
"balance": {
"type": "number"
"title": {
"type": "string"
}
}
},
"Name": {
"required": [ "firstName", "lastName" ],
"properties": {
"firstName": {
"type": "string"
@@ -297,40 +406,83 @@
}
}
},
"ToAccountInfo":{
"required": [ "id", "owner" ],
"GetAccountResponse": {
"properties": {
"id": {
"accountId": {
"type": "string"
},
"balance": {
"type": "number",
"format": "double"
}
}
},
"CreateAccountRequest": {
"properties": {
"customerId": {
"type": "string"
},
"initialBalance": {
"type": "number",
"format": "double"
},
"title": {
"type": "string"
},
"owner": {
"type": "string"
}
}
},
"Address": {
"required": [ "street1", "city", "state", "zipCode" ],
"CustomersQueryResponse": {
"properties": {
"street1": {
"customers": {
"type": "array",
"items": {
"$ref": "#/definitions/QuerySideCustomer"
}
}
}
},
"CreateMoneyTransferRequest": {
"properties": {
"amount": {
"type": "number",
"format": "double"
},
"fromAccountId": {
"type": "string"
},
"street2": {
"toAccountId": {
"type": "string"
}
}
},
"CustomerInfo": {
"properties": {
"address": {
"$ref": "#/definitions/Address"
},
"email": {
"type": "string"
},
"city": {
"name": {
"$ref": "#/definitions/Name"
},
"phoneNumber": {
"type": "string"
},
"state": {
"ssn": {
"type": "string"
}
}
},
"CustomerResponse": {
"properties": {
"customerInfo": {
"$ref": "#/definitions/CustomerInfo"
},
"zipCode": {
"id": {
"type": "string"
}
}
}
}
}
}

View File

@@ -33,4 +33,6 @@ include 'common-customers'
include 'customers-command-side-service'
include 'customers-query-side-service'
include 'common-auth-web'
include 'api-gateway-service'
include 'testutil-customers'

View 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"
}

View File

@@ -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");
}
}