use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method getEntity.
private DocumentEntity getEntity() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
map.put("name", "Poliana");
map.put("city", "Salvador");
map.put(CouchDBConstant.ID, "id");
List<Document> documents = Documents.of(map);
documents.forEach(entity::add);
return entity;
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldSaveSubDocument2.
@Test
public void shouldSaveSubDocument2() {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", 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).collect(Collectors.toList()).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")));
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldRetrieveListDocumentList.
@Test
public void shouldRetrieveListDocumentList() {
DocumentEntity entity = entityManager.insert(createDocumentList());
Document key = entity.find(CouchDBConstant.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 DefaultCouchDBDocumentCollectionManagerTest method shouldSaveMap.
@Test
public void shouldSaveMap() {
DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
String id = UUID.randomUUID().toString();
entity.add("properties", Collections.singletonMap("hallo", "Welt"));
entity.add("scope", "xxx");
entity.add("_id", id);
entityManager.insert(entity);
final DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id).and("scope").eq("xxx").build();
final Optional<DocumentEntity> optional = entityManager.select(query).findFirst();
Assertions.assertTrue(optional.isPresent());
DocumentEntity documentEntity = optional.get();
Document properties = documentEntity.find("properties").get();
Assertions.assertNotNull(properties);
}
use of jakarta.nosql.document.Document in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity entity = getEntity();
entity.remove(CouchDBConstant.ID);
entity = entityManager.insert(entity);
Document name = entity.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();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Aggregations