Search in sources :

Example 61 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DocumentRepositoryProxySortTest method shouldFindAll.

@Test
public void shouldFindAll() {
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(Person.builder().build()));
    Pagination pagination = getPagination();
    personRepository.findAll(pagination, Sorts.sorts().asc("name"));
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
    assertThat(query.getSorts(), Matchers.contains(Sort.asc("name")));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Test(org.junit.jupiter.api.Test)

Example 62 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultDocumentQueryPaginationTest method shouldOverrideSkipLimit.

@Test
public void shouldOverrideSkipLimit() {
    DocumentQuery query = select().from("column").build();
    Pagination pagination = Pagination.page(1).size(2);
    DocumentQueryPagination queryPagination = DocumentQueryPagination.of(query, pagination);
    assertNotNull(queryPagination);
    assertEquals(pagination.getLimit(), queryPagination.getLimit());
    assertEquals(pagination.getSkip(), queryPagination.getSkip());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Test(org.junit.jupiter.api.Test)

Example 63 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultDocumentQueryPaginationTest method shouldNext.

@Test
public void shouldNext() {
    DocumentQuery query = select().from("column").where("name").eq("Ada").build();
    Pagination pagination = Pagination.page(1).size(2);
    Pagination secondPage = pagination.next();
    DocumentQueryPagination queryPagination = DocumentQueryPagination.of(query, pagination);
    assertNotNull(queryPagination);
    assertEquals(pagination.getLimit(), queryPagination.getLimit());
    assertEquals(pagination.getSkip(), queryPagination.getSkip());
    isQueryEquals(query, pagination, queryPagination);
    DocumentQueryPagination next = queryPagination.next();
    isQueryEquals(query, secondPage, next);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Test(org.junit.jupiter.api.Test)

Example 64 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class ParamsBinderTest method shouldConvert2.

@Test
public void shouldConvert2() {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get();
    ClassMapping classMapping = mappings.get(Person.class);
    RepositoryDocumentObserverParser parser = new RepositoryDocumentObserverParser(classMapping);
    paramsBinder = new ParamsBinder(classMapping, converters);
    SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
    SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
    SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
    DocumentQueryParams queryParams = converter.apply(selectQuery, parser);
    Params params = queryParams.getParams();
    paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
    DocumentQuery query = queryParams.getQuery();
    DocumentCondition columnCondition = query.getCondition().get();
    List<DocumentCondition> conditions = columnCondition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    List<Object> values = conditions.stream().map(DocumentCondition::getDocument).map(Document::getValue).map(Value::get).collect(Collectors.toList());
    assertEquals(10, values.get(0));
    assertEquals("Ada", values.get(1));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) ParamsBinder(org.eclipse.jnosql.mapping.util.ParamsBinder) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) Params(jakarta.nosql.Params) Method(java.lang.reflect.Method) Document(jakarta.nosql.document.Document) SelectQuery(jakarta.nosql.query.SelectQuery) DocumentQuery(jakarta.nosql.document.DocumentQuery) SelectQueryConverter(jakarta.nosql.document.SelectQueryConverter) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) List(java.util.List) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 65 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DocumentPageTest method shouldExecutePaginationAsQuery.

@Test
public void shouldExecutePaginationAsQuery() {
    Pagination pagination = Pagination.page(1).size(1);
    DocumentQueryPagination queryPagination = DocumentQueryPagination.of(select().from("person").build(), pagination);
    DocumentQuery query = queryPagination;
    List<Person> people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(0L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(1L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(2L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(3L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(4L, people.stream().map(Person::getId).findFirst().orElse(-0L));
    queryPagination = queryPagination.next();
    query = queryPagination;
    people = subject.<Person>select(query).collect(Collectors.toList());
    assertEquals(5L, people.stream().map(Person::getId).findFirst().orElse(-0L));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Person(jakarta.nosql.tck.entities.Person) 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