use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldInserAsyncTTL.
@Test
public void shouldInserAsyncTTL() throws InterruptedException {
DocumentEntity entity = getEntity();
entityManagerAsync.insert(entity, Duration.ofSeconds(1L));
TimeUnit.SECONDS.sleep(2L);
Document id = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertTrue(entities.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerAsyncTest method shouldRemoveEntityAsyncCallBack.
@Test
public void shouldRemoveEntityAsyncCallBack() {
AtomicBoolean condition = new AtomicBoolean(false);
AtomicReference<List<DocumentEntity>> references = new AtomicReference<>();
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManagerAsync.delete(deleteQuery, d -> {
condition.set(true);
});
await().untilTrue(condition);
entityManagerAsync.select(query, references::set);
await().until(() -> references.get(), notNullValue());
assertFalse(references.get().isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery 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 = DocumentQueryBuilder.delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() throws InterruptedException {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
DocumentEntity entitySaved = entityManager.insert(entity);
Thread.sleep(1_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).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
use of org.jnosql.diana.api.document.DocumentQuery 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).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
Aggregations