|
22 | 22 | import jakarta.nosql.document.DocumentEntity; |
23 | 23 | import jakarta.nosql.document.DocumentQuery; |
24 | 24 | import org.eclipse.jnosql.diana.document.Documents; |
| 25 | +import org.eclipse.jnosql.diana.mongodb.document.type.Money; |
25 | 26 | import org.junit.jupiter.api.BeforeAll; |
26 | 27 | import org.junit.jupiter.api.Test; |
27 | 28 |
|
28 | 29 | import java.io.IOException; |
| 30 | +import java.math.BigDecimal; |
29 | 31 | import java.time.Duration; |
30 | 32 | import java.time.LocalDate; |
31 | | -import java.util.ArrayList; |
32 | | -import java.util.Arrays; |
33 | | -import java.util.Date; |
34 | | -import java.util.HashMap; |
35 | | -import java.util.List; |
36 | | -import java.util.Map; |
37 | | -import java.util.Optional; |
38 | | -import java.util.Random; |
| 33 | +import java.util.*; |
39 | 34 | import java.util.concurrent.ThreadLocalRandom; |
40 | 35 | import java.util.stream.Collectors; |
41 | 36 | import java.util.stream.StreamSupport; |
@@ -76,7 +71,7 @@ public void shouldThrowExceptionWhenInsertWithTTL() { |
76 | 71 | } |
77 | 72 |
|
78 | 73 | @Test |
79 | | - public void shouldUpdateSave() { |
| 74 | + public void shouldUpdate() { |
80 | 75 | DocumentEntity entity = getEntity(); |
81 | 76 | DocumentEntity documentEntity = entityManager.insert(entity); |
82 | 77 | Document newField = Documents.of("newField", "10"); |
@@ -482,6 +477,22 @@ public void shouldCount() { |
482 | 477 | assertTrue(entityManager.count(COLLECTION_NAME) > 0); |
483 | 478 | } |
484 | 479 |
|
| 480 | + @Test |
| 481 | + public void shouldCustomTypeWork() { |
| 482 | + DocumentEntity entity = getEntity(); |
| 483 | + Currency currency = Currency.getInstance("USD"); |
| 484 | + Money money = Money.of(currency, BigDecimal.valueOf(10D)); |
| 485 | + entity.add("money", money); |
| 486 | + DocumentEntity documentEntity = entityManager.insert(entity); |
| 487 | + Document id = documentEntity.find("_id").get(); |
| 488 | + DocumentQuery query = DocumentQuery.select().from(documentEntity.getName()) |
| 489 | + .where(id.getName()).eq(id.get()).build(); |
| 490 | + |
| 491 | + DocumentEntity result = entityManager.singleResult(query).get(); |
| 492 | + assertEquals(money, result.find("money").get().get(Money.class)); |
| 493 | + |
| 494 | + } |
| 495 | + |
485 | 496 | private DocumentEntity createSubdocumentList() { |
486 | 497 | DocumentEntity entity = DocumentEntity.of("AppointmentBook"); |
487 | 498 | entity.add(Document.of("_id", new Random().nextInt())); |
|
0 commit comments