use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("_key").get();
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(select).collect(Collectors.toList()).isEmpty());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity2.
@Test
public void shouldRemoveEntity2() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").get();
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(select).collect(Collectors.toList()).isEmpty());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() throws InterruptedException {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Thread.sleep(5_00L);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
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 CouchbaseDocumentCollectionManagerTest 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");
map.put("_id", "id");
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
Aggregations