BAEL-3917: Fix the integrations tests in ddd (#9708)

This commit is contained in:
kwoyke 2020-07-16 09:15:40 +02:00 committed by GitHub
parent 6ebf84fcb8
commit 3ccb59bf84
5 changed files with 75 additions and 9 deletions

View File

@ -0,0 +1,46 @@
package com.baeldung.ddd.order.config;
import org.bson.Document;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import java.math.BigDecimal;
import java.util.Collections;
@Configuration
public class CustomMongoConfiguration {
@Bean
public MongoCustomConversions customConversions() {
return new MongoCustomConversions(Collections.singletonList(DocumentToMoneyConverter.INSTANCE));
}
@ReadingConverter
enum DocumentToMoneyConverter implements Converter<Document, Money> {
INSTANCE;
@Override
public Money convert(Document source) {
Document money = source.get("money", Document.class);
return Money.of(getCurrency(money), getAmount(money));
}
private CurrencyUnit getCurrency(Document money) {
Document currency = money.get("currency", Document.class);
String currencyCode = currency.getString("code");
return CurrencyUnit.of(currencyCode);
}
private BigDecimal getAmount(Document money) {
String amount = money.getString("amount");
return BigDecimal.valueOf(Double.parseDouble(amount));
}
}
}

View File

@ -1,19 +1,24 @@
package com.baeldung.ddd.order.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.util.Arrays;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.math.BigDecimal;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
public class PersistOrderIntegrationTest {
public class PersistOrderLiveTest {
@Autowired
private JpaOrderRepository repository;

View File

@ -17,9 +17,14 @@ import com.baeldung.ddd.order.Order;
import com.baeldung.ddd.order.OrderLine;
import com.baeldung.ddd.order.Product;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
public class OrderMongoIntegrationTest {
public class OrderMongoLiveTest {
@Autowired
private OrderMongoRepository repo;

View File

@ -18,10 +18,15 @@ import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class CassandraDbOrderRepositoryIntegrationTest {
class CassandraDbOrderRepositoryLiveTest {
@Autowired
private SpringDataCassandraOrderRepository cassandraOrderRepository;

View File

@ -18,10 +18,15 @@ import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class MongoDbOrderRepositoryIntegrationTest {
class MongoDbOrderRepositoryLiveTest {
@Autowired
private SpringDataMongoOrderRepository mongoOrderRepository;