Search in sources :

Example 1 with Document

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

the class DefaultDocumentConditionTest method shouldCreateOrCondition.

@Test
public void shouldCreateOrCondition() {
    Document age = Document.of("age", 26);
    Document name = Document.of("name", "Otavio");
    DocumentCondition condition1 = DefaultDocumentCondition.of(name, Condition.EQUALS);
    DocumentCondition condition2 = DefaultDocumentCondition.of(age, Condition.GREATER_THAN);
    DocumentCondition and = condition1.or(condition2);
    Document andDocument = and.getDocument();
    assertEquals(Condition.OR, and.getCondition());
    assertEquals(Condition.OR.getNameField(), andDocument.getName());
    assertThat(andDocument.getValue().get(new TypeReference<List<DocumentCondition>>() {
    }), Matchers.containsInAnyOrder(condition1, condition2));
}
Also used : TypeReference(jakarta.nosql.TypeReference) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 2 with Document

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

the class DefaultDocumentConditionTest method shouldReturnErrorWhenBetweenIsNotIterable.

@Test
public void shouldReturnErrorWhenBetweenIsNotIterable() {
    assertThrows(IllegalArgumentException.class, () -> {
        Document document = Document.of("age", 12);
        DocumentCondition.between(document);
    });
}
Also used : Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Document

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

the class DefaultDocumentConditionTest method shouldReturnErrorWhenIterableHasMoreThanTwoElement2.

@Test
public void shouldReturnErrorWhenIterableHasMoreThanTwoElement2() {
    assertThrows(IllegalArgumentException.class, () -> {
        Document document = Document.of("age", Arrays.asList(12, 12, 12));
        DocumentCondition.between(document);
    });
}
Also used : Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 4 with Document

use of jakarta.nosql.document.Document 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 5 with Document

use of jakarta.nosql.document.Document 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)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14