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));
}
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);
});
}
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);
});
}
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));
}
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());
}
Aggregations