Search in sources :

Example 51 with DocumentCondition

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

the class DocumentRepositoryProxyTest method shouldConvertFieldToTheType.

@Test
public void shouldConvertFieldToTheType() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    personRepository.findByAge("120");
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(EQUALS, condition.getCondition());
    assertEquals(Document.of("age", 120), condition.getDocument());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 52 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByNameAndAgeGreaterEqualThan.

@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33, pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(AND, condition.getCondition());
    List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition columnCondition = conditions.get(0);
    DocumentCondition columnCondition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("Ada", columnCondition.getDocument().get());
    assertEquals("name", columnCondition.getDocument().getName());
    assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
    assertEquals(33, columnCondition2.getDocument().get());
    assertEquals("age", columnCondition2.getDocument().getName());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) List(java.util.List) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 53 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByAgeBetween.

@Test
public void shouldFindByAgeBetween() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAgeBetween(10, 15, pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(BETWEEN, condition.getCondition());
    List<Value> values = condition.getDocument().get(new TypeReference<List<Value>>() {
    });
    assertEquals(Arrays.asList(10, 15), values.stream().map(Value::get).collect(Collectors.toList()));
    assertTrue(condition.getDocument().getName().contains("age"));
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Value(jakarta.nosql.Value) List(java.util.List) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 54 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByAgeLessEqual.

@Test
public void shouldFindByAgeLessEqual() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByAgeLessThan(33, pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(LESSER_THAN, condition.getCondition());
    assertEquals(Document.of("age", 33), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentCondition

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

the class DocumentRepositoryProxyPaginationTest method shouldFindByNameLike.

@Test
public void shouldFindByNameLike() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    Pagination pagination = getPagination();
    personRepository.findByNameLike("Ada", pagination);
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(LIKE, condition.getCondition());
    assertEquals(Document.of("name", "Ada"), condition.getDocument());
    assertEquals(pagination.getSkip(), query.getSkip());
    assertEquals(pagination.getLimit(), query.getLimit());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Pagination(jakarta.nosql.mapping.Pagination) Person(jakarta.nosql.tck.entities.Person) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (jakarta.nosql.document.DocumentCondition)132 Test (org.junit.jupiter.api.Test)68 DocumentQuery (jakarta.nosql.document.DocumentQuery)64 Document (jakarta.nosql.document.Document)60 List (java.util.List)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)4 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)4