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