use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldUpdateSave.
@Test
public void shouldUpdateSave() {
DocumentEntity entity = DocumentEntityGerator.getEntity();
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 jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldFindOrderByNameDesc.
@Test
public void shouldFindOrderByNameDesc() throws InterruptedException {
final DocumentEntity poliana = DocumentEntityGerator.getEntity();
final DocumentEntity otavio = DocumentEntityGerator.getEntity();
poliana.add("name", "poliana");
otavio.add("name", "otavio");
otavio.add("_id", "id2");
entityManager.insert(Arrays.asList(poliana, otavio));
SECONDS.sleep(1L);
DocumentQuery query = DocumentQuery.select().from("person").orderBy("name").desc().build();
String[] names = entityManager.select(query).map(d -> d.find("name")).filter(Optional::isPresent).map(Optional::get).map(d -> d.get(String.class)).toArray(String[]::new);
assertArrayEquals(names, new String[] { "poliana", "otavio" });
}
use of jakarta.nosql.document.DocumentEntity 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(DocumentEntityGerator.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 jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method shouldCount.
@Test
public void shouldCount() throws InterruptedException {
DocumentEntity entity = DocumentEntityGerator.getEntity();
DocumentEntity entity2 = DocumentEntityGerator.getEntity();
entity2.add(Document.of("_id", "test"));
entityManager.insert(entity);
entityManager.insert(entity2);
SECONDS.sleep(1L);
assertTrue(entityManager.count(DocumentEntityGerator.COLLECTION_NAME) > 0);
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana-driver by eclipse.
the class ElasticsearchDocumentCollectionManagerTest method createSubdocumentList.
private DocumentEntity createSubdocumentList() {
DocumentEntity entity = DocumentEntity.of(DocumentEntityGerator.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