|
22 | 22 | import jakarta.nosql.document.DocumentEntity; |
23 | 23 | import jakarta.nosql.document.DocumentQuery; |
24 | 24 | import org.eclipse.jnosql.communication.document.Documents; |
| 25 | +import org.junit.jupiter.api.Assertions; |
25 | 26 | import org.junit.jupiter.api.BeforeEach; |
26 | 27 | import org.junit.jupiter.api.Test; |
27 | 28 |
|
28 | 29 | import java.util.ArrayList; |
| 30 | +import java.util.Collections; |
29 | 31 | import java.util.HashMap; |
30 | 32 | import java.util.List; |
31 | 33 | import java.util.Map; |
| 34 | +import java.util.Optional; |
| 35 | +import java.util.UUID; |
| 36 | +import java.util.concurrent.ThreadLocalRandom; |
32 | 37 | import java.util.stream.Collectors; |
33 | 38 |
|
34 | 39 | import static jakarta.nosql.document.DocumentDeleteQuery.delete; |
@@ -230,6 +235,25 @@ public void shouldSaveSubDocument2() { |
230 | 235 | assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))); |
231 | 236 | } |
232 | 237 |
|
| 238 | + @Test |
| 239 | + public void shouldSaveMap() { |
| 240 | + DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME); |
| 241 | + String id = UUID.randomUUID().toString(); |
| 242 | + entity.add("properties", Collections.singletonMap("hallo", "Welt")); |
| 243 | + entity.add("scope", "xxx"); |
| 244 | + entity.add("_id", id); |
| 245 | + entityManager.insert(entity); |
| 246 | + final DocumentQuery query = select().from(COLLECTION_NAME) |
| 247 | + .where("_id").eq(id).and("scope").eq("xxx").build(); |
| 248 | + final Optional<DocumentEntity> optional = entityManager.select(query).findFirst(); |
| 249 | + Assertions.assertTrue(optional.isPresent()); |
| 250 | + DocumentEntity documentEntity = optional.get(); |
| 251 | + Document properties = documentEntity.find("properties").get(); |
| 252 | + Map<String, Object> map = properties.get(new TypeReference<Map<String, Object>>() { |
| 253 | + }); |
| 254 | + Assertions.assertNotNull(map); |
| 255 | + } |
| 256 | + |
233 | 257 | private DocumentEntity createDocumentList() { |
234 | 258 | DocumentEntity entity = DocumentEntity.of("AppointmentBook"); |
235 | 259 | List<List<Document>> documents = new ArrayList<>(); |
|
0 commit comments