use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRunN1QlParameters.
@Test
public void shouldRunN1QlParameters() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
JsonObject params = JsonObject.create().put("name", "Poliana");
List<DocumentEntity> entities = entityManager.n1qlQuery("select * from jnosql where name = $name", params).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertEquals(1, entities.size());
}
use of jakarta.nosql.document.DocumentEntity 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.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRunN1QlStatement.
@Test
public void shouldRunN1QlStatement() {
DocumentEntity entity = getEntity();
entityManager.insert(entity);
Statement statement = Select.select("*").from("jnosql").where(x("name").eq("\"Poliana\""));
List<DocumentEntity> entities = entityManager.n1qlQuery(statement).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertEquals(1, entities.size());
}
use of jakarta.nosql.document.DocumentEntity 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;
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document name = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Aggregations