Search in sources :

Example 46 with DocumentCondition

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

the class DeleteQueryParserTest method shouldReturnParserQuery23.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete  from God where name = \"Ada\" and age = 20" })
public void shouldReturnParserQuery23(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, contains(eq(Document.of("name", "Ada")), eq(Document.of("age", 20L))));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with DocumentCondition

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

the class AbstractMapperQuery method likeImpl.

protected void likeImpl(String value) {
    requireNonNull(value, "value is required");
    DocumentCondition newCondition = DocumentCondition.like(Document.of(mapping.getColumnField(name), getValue(value)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 48 with DocumentCondition

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

the class AbstractMapperQuery method gtImpl.

protected <T> void gtImpl(T value) {
    requireNonNull(value, "value is required");
    DocumentCondition newCondition = DocumentCondition.gt(Document.of(mapping.getColumnField(name), getValue(value)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 49 with DocumentCondition

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

the class DocumentRepositoryProxyTest method shouldFindByNameInstance.

@Test
public void shouldFindByNameInstance() {
    when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
    personRepository.findByName("name");
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).singleResult(captor.capture());
    DocumentQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertNotNull(personRepository.findByName("name"));
    when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
    assertNull(personRepository.findByName("name"));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 50 with DocumentCondition

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

the class DocumentRepositoryProxyTest 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));
    personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33);
    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());
    assertTrue(columnCondition.getDocument().getName().contains("name"));
    assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
    assertEquals(33, columnCondition2.getDocument().get());
    assertTrue(columnCondition2.getDocument().getName().contains("age"));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) 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