use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsyncTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
AtomicReference<DocumentEntity> entityAtomic = new AtomicReference<>();
entityManager.insert(getEntity(), entityAtomic::set);
await().until(entityAtomic::get, notNullValue(DocumentEntity.class));
DocumentEntity entity = entityAtomic.get();
Document document = entity.find("name").get();
DocumentDeleteQuery deleteQuery = delete().from(entity.getName()).where(document.getName()).eq(document.get()).build();
entityManager.delete(deleteQuery);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsyncTest 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 org.jnosql.diana.api.document.Document in project jnosql-artemis by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertToDocumentWhenHaConverter.
@Test
public void shouldConvertToDocumentWhenHaConverter() {
Worker worker = new Worker();
Job job = new Job();
job.setCity("Sao Paulo");
job.setDescription("Java Developer");
worker.setName("Bob");
worker.setSalary(new Money("BRL", BigDecimal.TEN));
worker.setJob(job);
DocumentEntity entity = converter.toDocument(worker);
assertEquals("Worker", entity.getName());
assertEquals("Bob", entity.find("name").get().get());
Document subDocument = entity.find("job").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, Matchers.containsInAnyOrder(Document.of("city", "Sao Paulo"), Document.of("description", "Java Developer")));
assertEquals("BRL 10", entity.find("money").get().get());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsyncWithNativeQueryMapParam.
@Test
public void shouldFindAsyncWithNativeQueryMapParam() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find(OrientDBConverter.RID_FIELD);
Optional<Document> name = entity.find("name");
AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
Map<String, Object> params = new HashMap<>();
params.put("id", id.get().get());
params.put("name", name.get().get());
entityManagerAsync.sql("select * from person where @rid = :id and name = :name", reference::set, params);
await().until(reference::get, notNullValue(List.class));
assertFalse(reference.get().isEmpty());
assertEquals(reference.get().get(0), entity);
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSQL.
@Test
public void shouldSQL() {
DocumentEntity entity = entityManager.insert(getEntity());
Optional<Document> id = entity.find("name");
List<DocumentEntity> entities = entityManager.sql("select * from person where name = ?", id.get().get());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
Aggregations