use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldSelectAll.
@Test
public void shouldSelectAll() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
DocumentQuery query = select().from(COLLECTION_NAME).build();
Optional<Document> name = entity.find("name");
List<DocumentEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
assertTrue(entities.size() >= 4);
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class SearchQueryTest method shouldSearchElement3.
@Test
public void shouldSearchElement3() {
MatchQuery match = SearchQuery.match("Salvador").field("name");
SearchQuery query = new SearchQuery("index-diana", match);
List<DocumentEntity> entities = entityManager.search(query);
assertEquals(1, entities.size());
List<String> result = entities.stream().flatMap(e -> e.getDocuments().stream()).filter(d -> "name".equals(d.getName())).map(d -> d.get(String.class)).collect(Collectors.toList());
assertThat(result, containsInAnyOrder("Salvador"));
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class DocumentEntityGerator method getEntity.
static 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 org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerAsyncTest method shouldReturnAll.
@Test
public void shouldReturnAll() {
DocumentEntity entity = getEntity();
entityManagerAsync.insert(entity);
DocumentQuery query = select().from(COLLECTION_NAME).build();
AtomicBoolean condition = new AtomicBoolean(false);
AtomicReference<List<DocumentEntity>> result = new AtomicReference<>();
entityManagerAsync.select(query, l -> {
condition.set(true);
result.set(l);
});
Awaitility.await().untilTrue(condition);
List<DocumentEntity> entities = result.get();
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method createSubdocumentList.
private DocumentEntity createSubdocumentList() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
entity.add(Document.of("_id", "ids"));
List<List<Document>> documents = new ArrayList<>();
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.PHONE), Document.of("information", "phone")));
entity.add(Document.of("contacts", documents));
return entity;
}
Aggregations