use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DefaultDocumentMapperSelectBuilderTest method shouldConvertField.
@Test
public void shouldConvertField() {
DocumentQuery query = mapperBuilder.selectFrom(Person.class).where("id").eq("20").build();
DocumentQuery queryExpected = select().from("Person").where("_id").eq(20L).build();
assertEquals(queryExpected, query);
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentReactiveRepositoryProxyTest method shouldFindByNameANDAge.
@Test
public void shouldFindByNameANDAge() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.of(ada));
Publisher<Person> publisher = personRepository.findByNameAndAge("name", 20);
final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
publisher.subscribe(subscriber);
AtomicReference<List<Person>> reference = new AtomicReference<>();
final CompletionStage<List<Person>> completion = subscriber.getCompletion();
completion.thenAccept(reference::set);
final List<Person> people = reference.get();
Assertions.assertNotNull(people);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
assertThat(people, Matchers.contains(ada));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldFindDocument.
@Test
public void shouldFindDocument() {
DocumentEntity entity = entityManager.insert(getEntity());
Document id = entity.find(KEY_NAME).get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertFalse(entities.isEmpty());
DocumentEntity documentEntity = entities.get(0);
assertEquals(entity.find(KEY_NAME).get().getValue().get(String.class), documentEntity.find(KEY_NAME).get().getValue().get(String.class));
assertEquals(entity.find("name").get(), documentEntity.find("name").get());
assertEquals(entity.find("city").get(), documentEntity.find("city").get());
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class ArangoDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find(KEY_NAME).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 ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity.
@Test
public void shouldRemoveEntity() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document id = documentEntity.find("_key").get();
DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(select).collect(Collectors.toList()).isEmpty());
}
Aggregations