use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldFindDocumentByName.
@Test
public void shouldFindDocumentByName() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
assertThat(entities, contains(entity));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class DefaultCouchDBDocumentCollectionManagerTest method shouldSelectEmptyResult.
@Test
public void shouldSelectEmptyResult() {
DocumentQuery query = select().from(COLLECTION_NAME).where("no_field").eq("not_found").build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertTrue(entities.isEmpty());
}
use of jakarta.nosql.document.DocumentQuery 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.DocumentQuery 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.DocumentQuery 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);
}
Aggregations