use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.
the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.
@Test
public void shouldSelectWhereNameBetween() {
String documentCollection = "documentCollection";
Number valueA = 10;
Number valueB = 20;
DocumentQuery query = select().from(documentCollection).where("name").between(valueA, valueB).build();
DocumentCondition condition = query.getCondition().get();
Document document = condition.getDocument();
assertTrue(query.getDocuments().isEmpty());
assertEquals(documentCollection, query.getDocumentCollection());
assertEquals(Condition.BETWEEN, condition.getCondition());
assertEquals("name", document.getName());
assertThat(document.get(new TypeReference<List<Number>>() {
}), Matchers.contains(10, 20));
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.
the class BaseQueryBuilder method betweenImpl.
protected void betweenImpl(Number valueA, Number valueB) {
requireNonNull(valueA, "valueA is required");
requireNonNull(valueB, "valueB is required");
DocumentCondition newCondition = DocumentCondition.between(Document.of(name, asList(valueA, valueB)));
appendCondition(newCondition);
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.
the class BaseQueryBuilder method inImpl.
protected <T> void inImpl(Iterable<T> values) {
requireNonNull(values, "values is required");
DocumentCondition newCondition = DocumentCondition.in(Document.of(name, values));
appendCondition(newCondition);
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateTest method shouldDeleteEntity.
@Test
public void shouldDeleteEntity() {
subject.delete(Person.class, "10");
ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
verify(managerMock).delete(queryCaptor.capture());
DocumentDeleteQuery query = queryCaptor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), condition);
}
use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-artemis by eclipse.
the class DocumentQueryDeleteParserTest method shouldDeleteByNameOrAge.
@Test
public void shouldDeleteByNameOrAge() {
DocumentDeleteQuery query = parser.parse("deleteByNameOrAge", new Object[] { "name", 10 }, classRepresentation, converters);
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(Condition.OR, condition.getCondition());
List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
DocumentCondition condition1 = conditions.get(0);
assertEquals(Condition.EQUALS, condition1.getCondition());
assertEquals(Document.of("name", "name"), condition1.getDocument());
DocumentCondition condition2 = conditions.get(1);
assertEquals(Condition.EQUALS, condition2.getCondition());
assertEquals(Document.of("age", 10), condition2.getDocument());
}
Aggregations