Skip to content

Commit

Permalink
BAEL-3917: Fix the integrations tests in ddd (eugenp#9708)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoyke authored Jul 16, 2020
1 parent cf643dc commit 16f8c02
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
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;
Expand Down

0 comments on commit 16f8c02

Please sign in to comment.