Simplified project structure
This commit is contained in:
14
java-spring/rest-api-integration-tests/build.gradle
Normal file
14
java-spring/rest-api-integration-tests/build.gradle
Normal file
@@ -0,0 +1,14 @@
|
||||
apply plugin: VerifyMongoDBConfigurationPlugin
|
||||
|
||||
dependencies {
|
||||
testCompile project(":common-auth-web")
|
||||
testCompile project(":transactions-service")
|
||||
testCompile project(":accounts-service")
|
||||
testCompile project(":accounts-view-service")
|
||||
testCompile project(":customers-service")
|
||||
testCompile project(":customers-view-service")
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
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.customers.queryside.common.QuerySideCustomer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
|
||||
|
||||
/**
|
||||
* Created by Main on 15.02.2016.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest({"server.port=0", "management.port=0"})
|
||||
public class BankingAuthTest {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
|
||||
}
|
||||
|
||||
private String baseUrl(String path) {
|
||||
return "http://localhost:" + port + "/api" + path;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateCustomerAndLogin() {
|
||||
CustomerInfo customerInfo = generateCustomerInfo();
|
||||
|
||||
final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody();
|
||||
final String customerId = customerResponse.getId();
|
||||
|
||||
Assert.assertNotNull(customerId);
|
||||
Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo());
|
||||
|
||||
customersTestUtils.assertCustomerResponse(customerId, customerInfo);
|
||||
|
||||
final QuerySideCustomer loginQuerySideCustomer = restTemplate.postForEntity(baseUrl("/login"), customerInfo.getUserCredentials(), QuerySideCustomer.class).getBody();
|
||||
|
||||
customersTestUtils.assertQuerySideCustomerEqualscCustomerInfo(loginQuerySideCustomer, customerResponse.getCustomerInfo());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.AbstractRestAPITest;
|
||||
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest({"server.port=0", "management.port=0"})
|
||||
public class BankingWebIntegrationTest extends AbstractRestAPITest {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String baseUrl(String path) {
|
||||
return "http://localhost:" + port + "/api" + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomersTestUtils getCustomersTestUtils() {
|
||||
return customersTestUtils;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Override
|
||||
public RestTemplate getRestTemplate() {
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import io.eventuate.javaclient.spring.jdbc.EmbeddedTestAggregateStoreConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.accountsservice.web.AccountsWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.accountsviewservice.web.AccountViewWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.customersservice.web.CustomersWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.customersviewservice.web.CustomersViewWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.transactionsservice.web.MoneyTransferWebConfiguration;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.RestTemplateErrorHandler;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
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.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@Import({AccountsWebConfiguration.class,
|
||||
MoneyTransferWebConfiguration.class,
|
||||
AccountViewWebConfiguration.class,
|
||||
CustomersViewWebConfiguration.class,
|
||||
CustomersWebConfiguration.class,
|
||||
EmbeddedTestAggregateStoreConfiguration.class,
|
||||
AuthConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
public class BankingWebTestConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public HttpMessageConverters customConverters() {
|
||||
HttpMessageConverter<?> additional = new MappingJackson2HttpMessageConverter();
|
||||
return new HttpMessageConverters(additional);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(HttpMessageConverters converters) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpMessageConverter<?> httpMessageConverter = converters.getConverters().get(0);
|
||||
List<? extends HttpMessageConverter<?>> httpMessageConverters = Arrays.asList(new MappingJackson2HttpMessageConverter());
|
||||
restTemplate.setMessageConverters((List<HttpMessageConverter<?>>) httpMessageConverters);
|
||||
|
||||
restTemplate.setErrorHandler(new RestTemplateErrorHandler());
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user