use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldSaveMap.
@Test
public void shouldSaveMap() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
String id = UUID.randomUUID().toString();
entity.add("properties", Collections.singletonMap("hallo", "Welt"));
entity.add("scope", "xxx");
entity.add("_id", id);
entityManager.insert(entity);
final DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id).and("scope").eq("xxx").build();
final Optional<DocumentEntity> optional = entityManager.select(query).findFirst();
Assertions.assertTrue(optional.isPresent());
DocumentEntity documentEntity = optional.get();
Document properties = documentEntity.find("properties").get();
Map<String, Object> map = properties.get(new TypeReference<Map<String, Object>>() {
});
Assertions.assertNotNull(map);
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldRetrieveListDocumentList.
@Test
public void shouldRetrieveListDocumentList() {
DocumentEntity entity = entityManager.insert(createDocumentList());
Document key = entity.find("_id").get();
DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method getEntity.
private DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldInsert.
@Test
public void shouldInsert() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
assertTrue(documentEntity.getDocuments().stream().map(Document::getName).anyMatch(s -> s.equals("_id")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldUpdate.
@Test
public void shouldUpdate() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
Document newField = Documents.of("newField", "10");
entity.add(newField);
DocumentEntity updated = entityManager.update(entity);
assertEquals(newField, updated.find("newField").get());
}
Aggregations