use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).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 org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityById.
@Test
public void shouldRemoveEntityById() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("_id").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();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldFindDocumentById.
@Test
public void shouldFindDocumentById() {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() throws InterruptedException {
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();
TimeUnit.SECONDS.sleep(1L);
entityManager.delete(deleteQuery);
TimeUnit.SECONDS.sleep(1L);
List<DocumentEntity> entities = entityManager.select(query);
System.out.println(entities);
assertTrue(entities.isEmpty());
}
use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest 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("_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, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Aggregations