forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-3917: Fix the integrations tests in ddd (eugenp#9708)
- Loading branch information
Showing
5 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
ddd/src/main/java/com/baeldung/ddd/order/config/CustomMongoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
...rder/jpa/PersistOrderIntegrationTest.java → ...g/ddd/order/jpa/PersistOrderLiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters