Search in sources :

Example 6 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldAppendAnd.

@Test
public void shouldAppendAnd() {
    DocumentCondition eq = DocumentCondition.eq(Document.of("name", "otavio"));
    DocumentCondition gt = DocumentCondition.gt(Document.of("age", 10));
    DocumentCondition and = DocumentCondition.and(eq, gt);
    assertEquals(Condition.AND, and.getCondition());
    List<DocumentCondition> conditions = and.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    assertThat(conditions, Matchers.containsInAnyOrder(eq, gt));
}
Also used : List(java.util.List) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 7 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldReturnInClause.

@Test
public void shouldReturnInClause() {
    Document column = Document.of("age", Arrays.asList(12, 13));
    DocumentCondition in = DocumentCondition.in(column);
    assertEquals(Condition.IN, in.getCondition());
    Iterable<Integer> integers = in.getDocument().get(new TypeReference<Iterable<Integer>>() {
    });
    assertThat(integers, contains(12, 13));
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 8 with DocumentCondition

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

the class DefaultDocumentQueryParserTest method shouldReturnEmptySingleResult.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    Mockito.when(manager.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.empty());
    DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
    prepare.bind("age", 12);
    final Optional<DocumentEntity> result = prepare.getSingleResult();
    Mockito.verify(manager).select(captor.capture());
    DocumentQuery columnQuery = captor.getValue();
    DocumentCondition columnCondition = columnQuery.getCondition().get();
    Document column = columnCondition.getDocument();
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("age", column.getName());
    assertEquals(12, column.get());
    assertFalse(result.isPresent());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with DocumentCondition

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentQuery query = select().from(documentCollection).where("name").eq(name).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals(name, document.get());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 10 with DocumentCondition

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

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameNot.

@Test
public void shouldSelectWhereNameNot() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentQuery query = select().from(documentCollection).where("name").not().eq(name).build();
    DocumentCondition condition = query.getCondition().get();
    Document column = condition.getDocument();
    DocumentCondition negate = column.get(DocumentCondition.class);
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.NOT, condition.getCondition());
    assertEquals(Condition.EQUALS, negate.getCondition());
    assertEquals("name", negate.getDocument().getName());
    assertEquals(name, negate.getDocument().get());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Document(jakarta.nosql.document.Document) 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