use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldUpdateSave.
@Test
public void shouldUpdateSave() {
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());
}
use of org.jnosql.diana.api.document.DocumentEntity 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).isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find(KEY_NAME).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRunN1QlStatement.
@Test
public void shouldRunN1QlStatement() {
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
DocumentEntity entity = getEntity();
entityManager.insert(entity);
Statement statement = Select.select("*").from("jnosql").where(x("name").eq("\"Poliana\""));
entityManagerAsync.n1qlQuery(statement, references::set);
assertFalse(references.get().isEmpty());
assertEquals(1, references.get().size());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method setUp.
@BeforeEach
public void setUp() {
CouchbaseDocumentConfiguration configuration = new CouchbaseDocumentConfiguration();
CouhbaseDocumentCollectionManagerFactory managerFactory = configuration.get();
entityManagerAsync = managerFactory.getAsync(CouchbaseUtil.BUCKET_NAME);
entityManager = managerFactory.get(CouchbaseUtil.BUCKET_NAME);
DocumentEntity documentEntity = getEntity();
Document id = documentEntity.find("name").get();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManagerAsync.delete(deleteQuery);
}
Aggregations