| 
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;  | 
@@ -178,22 +183,20 @@ public void shouldSelectWithCouchDBDocumentQuery() {  | 
178 | 183 | 
 
  | 
179 | 184 |     @Test  | 
180 | 185 |     public void shouldConvertFromListSubdocumentList() {  | 
181 |  | -        DocumentEntity entity = createSubdocumentList();  | 
 | 186 | +        DocumentEntity entity = createDocumentList();  | 
182 | 187 |         entityManager.insert(entity);  | 
183 | 188 | 
 
  | 
184 | 189 |     }  | 
185 | 190 | 
 
  | 
186 | 191 |     @Test  | 
187 |  | -    public void shouldRetrieveListSubdocumentList() {  | 
188 |  | -        DocumentEntity entity = entityManager.insert(createSubdocumentList());  | 
 | 192 | +    public void shouldRetrieveListDocumentList() {  | 
 | 193 | +        DocumentEntity entity = entityManager.insert(createDocumentList());  | 
189 | 194 |         Document key = entity.find(CouchDBConstant.ID).get();  | 
190 | 195 |         DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();  | 
191 | 196 | 
 
  | 
192 | 197 |         DocumentEntity documentEntity = entityManager.singleResult(query).get();  | 
193 | 198 |         assertNotNull(documentEntity);  | 
194 |  | - | 
195 | 199 |         List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();  | 
196 |  | - | 
197 | 200 |         assertEquals(3, contacts.size());  | 
198 | 201 |         assertTrue(contacts.stream().allMatch(d -> d.size() == 3));  | 
199 | 202 |     }  | 
@@ -232,7 +235,24 @@ public void shouldSaveSubDocument2() {  | 
232 | 235 |         assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));  | 
233 | 236 |     }  | 
234 | 237 | 
 
  | 
235 |  | -    private DocumentEntity createSubdocumentList() {  | 
 | 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 | +        Assertions.assertNotNull(properties);  | 
 | 253 | +    }  | 
 | 254 | + | 
 | 255 | +    private DocumentEntity createDocumentList() {  | 
236 | 256 |         DocumentEntity entity = DocumentEntity.of("AppointmentBook");  | 
237 | 257 |         List<List<Document>> documents = new ArrayList<>();  | 
238 | 258 | 
 
  | 
 | 
0 commit comments