- refactored the tests

- moved some dto classes into common module
This commit is contained in:
Main
2016-08-09 22:58:00 +03:00
parent 39309f23a1
commit b0855ebd81
9 changed files with 66 additions and 45 deletions

View File

@@ -1,7 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import io.eventuate.EntityWithIdAndVersion;
import io.eventuate.EntityWithMetadata;
import io.eventuate.EventuateAggregateStore;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
@@ -9,8 +8,6 @@ import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.t
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.TransferState;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -18,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import rx.Observable;
import java.math.BigDecimal;
@@ -30,39 +26,39 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil
@IntegrationTest
public class AccountQuerySideIntegrationTest {
@Autowired
private AccountService accountService;
@Autowired
private AccountService accountService;
@Autowired
private MoneyTransferService moneyTransferService;
@Autowired
private MoneyTransferService moneyTransferService;
@Autowired
private EventuateAggregateStore eventStore;
@Autowired
private EventuateAggregateStore eventStore;
@Autowired
private AccountQueryService accountQueryService;
@Autowired
private AccountQueryService accountQueryService;
@Test
public void shouldUpdateQuerySide() throws Exception {
@Test
public void shouldUpdateQuerySide() throws Exception {
final EntityWithIdAndVersion<Account> fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), ""));
final EntityWithIdAndVersion<Account> fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), ""));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), ""));
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), ""));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
eventually(
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
eventually(
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
eventually(
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
accountInfo -> Assert.assertEquals(70*100, accountInfo.getBalance()));
eventually(
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
accountInfo -> Assert.assertEquals(380*100, accountInfo.getBalance()));
}
eventually(
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
accountInfo -> Assert.assertEquals(70 * 100, accountInfo.getBalance()));
eventually(
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
accountInfo -> Assert.assertEquals(380 * 100, accountInfo.getBalance()));
}
}

View File

@@ -19,10 +19,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.concurrent.CompletableFuture;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateToAccountInfo;
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.

View File

@@ -8,7 +8,7 @@ import org.junit.Test;
import java.util.List;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
public class CustomerTest {
@@ -26,4 +26,6 @@ public class CustomerTest {
customer.applyEvent(events.get(0));
Assert.assertEquals(customerInfo, customer.getCustomerInfo());
}
}

View File

@@ -13,7 +13,7 @@ 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;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CustomersCommandSideServiceTestConfiguration.class)

View File

@@ -1,9 +1,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 net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -18,8 +16,7 @@ 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;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CustomersQuerySideServiceTestConfiguration.class)

View File

@@ -3,8 +3,11 @@ package net.chrisrichardson.eventstore.examples.bank.web;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.AbstractRestAPITest;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.AuthenticatedRestTemplate;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
public class EndToEndTest extends AbstractRestAPITest {
private String getenv(String name, String defaultValue) {
@@ -12,10 +15,22 @@ public class EndToEndTest extends AbstractRestAPITest {
return x == null ? defaultValue : x;
}
CustomersTestUtils customersTestUtils;
@PostConstruct
private void init() {
customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/"));
}
public String baseUrl(String path) {
return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + 8080 + "/" + path;
}
@Override
public CustomersTestUtils getCustomersTestUtils() {
return customersTestUtils;
}
RestTemplate restTemplate = new RestTemplate();
@Override

View File

@@ -4,7 +4,7 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust
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.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -18,7 +18,7 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.CustomersTestUtils.generateCustomerInfo;
/**
* Created by Main on 15.02.2016.

View File

@@ -2,6 +2,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.AbstractRestAPITest;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.AuthenticatedRestTemplate;
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;
@@ -11,6 +12,8 @@ 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
@@ -20,11 +23,23 @@ 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 + "/" + path;
}
@Override
public CustomersTestUtils getCustomersTestUtils() {
return customersTestUtils;
}
@Autowired
RestTemplate restTemplate;

View File

@@ -12,14 +12,10 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.C
import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.CreateMoneyTransferResponse;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;