Search in sources :

Example 66 with DocumentQuery

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);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 67 with DocumentQuery

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));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 68 with DocumentQuery

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 69 with DocumentQuery

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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) TypeReference(jakarta.nosql.TypeReference) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) ArangoDB(com.arangodb.ArangoDB) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 70 with DocumentQuery

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());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (jakarta.nosql.document.DocumentQuery)292 Test (org.junit.jupiter.api.Test)234 DocumentEntity (jakarta.nosql.document.DocumentEntity)123 Document (jakarta.nosql.document.Document)98 DocumentCondition (jakarta.nosql.document.DocumentCondition)64 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)55 Person (jakarta.nosql.tck.entities.Person)50 List (java.util.List)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 Arrays.asList (java.util.Arrays.asList)34 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ArrayList (java.util.ArrayList)26 Collectors (java.util.stream.Collectors)19 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.contains (org.hamcrest.Matchers.contains)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)16 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)16