use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerTest method shouldCustomTypeWork.
@Test
public void shouldCustomTypeWork() {
DocumentEntity entity = getEntity();
Currency currency = Currency.getInstance("USD");
Money money = Money.of(currency, BigDecimal.valueOf(10D));
entity.add("money", money);
DocumentEntity documentEntity = entityManager.insert(entity);
Document id = documentEntity.find("_id").get();
DocumentQuery query = DocumentQuery.select().from(documentEntity.getName()).where(id.getName()).eq(id.get()).build();
DocumentEntity result = entityManager.singleResult(query).get();
assertEquals(money, result.find("money").get().get(Money.class));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Document id = entitySaved.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldInsert.
@Test
public void shouldInsert() {
DocumentEntity entity = getEntity();
DocumentEntity documentEntity = entityManager.insert(entity);
assertNotNull(documentEntity);
Optional<Document> document = documentEntity.find(OrientDBConverter.RID_FIELD);
assertTrue(document.isPresent());
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find("_id").get();
DocumentQuery query = select().from("AppointmentBook").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.Document in project jnosql-diana-driver by eclipse.
the class OrientDBDocumentCollectionManagerTest method shouldLiveUpdateCallback.
@Test
@Disabled
public void shouldLiveUpdateCallback() {
AtomicBoolean condition = new AtomicBoolean(false);
List<DocumentEntity> entities = new ArrayList<>();
OrientDBLiveUpdateCallback<DocumentEntity> callback = d -> {
entities.add(d);
condition.set(true);
};
DocumentEntity entity = entityManager.insert(getEntity());
DocumentQuery query = select().from(COLLECTION_NAME).build();
entityManager.live(query, OrientDBLiveCallbackBuilder.builder().onUpdate(callback).build());
Document newName = Document.of("name", "Lucas");
entity.add(newName);
entityManager.update(entity);
await().untilTrue(condition);
assertFalse(entities.isEmpty());
assertFalse(entities.isEmpty());
}
Aggregations