use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class SelectQueryParserTest method shouldReturnParserQuery26.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where name = \"Ada\" and age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"} and birthday =" + " convert(\"2007-12-03\", java.time.LocalDate)" })
public void shouldReturnParserQuery26(String query) {
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
parser.query(query, documentCollection, observer);
Mockito.verify(documentCollection).select(captor.capture());
DocumentQuery documentQuery = captor.getValue();
checkBaseQuery(documentQuery, 0L, 0L);
assertTrue(documentQuery.getCondition().isPresent());
DocumentCondition condition = documentQuery.getCondition().get();
Document document = condition.getDocument();
assertEquals(Condition.AND, condition.getCondition());
List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
});
assertEquals(Condition.EQUALS, conditions.get(0).getCondition());
assertEquals(Condition.EQUALS, conditions.get(1).getCondition());
assertEquals(Condition.OR, conditions.get(2).getCondition());
assertEquals(Condition.EQUALS, conditions.get(3).getCondition());
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class BaseDocumentRepository method getQuery.
protected DocumentQuery getQuery(Method method, Object[] args) {
SelectMethodProvider methodProvider = SelectMethodProvider.get();
SelectQuery selectQuery = methodProvider.apply(method, getClassMapping().getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
DocumentQueryParams queryParams = converter.apply(selectQuery, getParser());
DocumentQuery query = queryParams.getQuery();
Params params = queryParams.getParams();
getParamsBinder().bind(params, args, method);
return getQuerySorts(args, query);
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DocumentReactiveRepositoryProxyTest method shouldFindAll.
@Test
public void shouldFindAll() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
List<Person> persons = personRepository.findAll();
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
assertFalse(query.getCondition().isPresent());
assertEquals("Person", query.getDocumentCollection());
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class AbstractReactiveDocumentRepositoryProxy method invoke.
@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
RepositoryType type = ReactiveRepositoryType.of(method);
Class<?> typeClass = getClassMapping().getClassInstance();
switch(type) {
case DEFAULT:
return method.invoke(getRepository(), args);
case FIND_BY:
DocumentQuery query = getQuery(method, args);
return executeQuery(method, args, typeClass, query);
case FIND_ALL:
DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
case DELETE_BY:
DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
Iterable<Void> iterable = () -> {
getTemplate().delete(documentDeleteQuery);
return Collections.emptyIterator();
};
return ReactiveStreams.fromIterable(iterable).buildRs();
case OBJECT_METHOD:
return method.invoke(this, args);
case JNOSQL_QUERY:
DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
return methodReturn.execute();
default:
return Void.class;
}
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.
the class DefaultReactiveDocumentTemplateTest method shouldSelect.
@Test
public void shouldSelect() {
DocumentQuery query = Mockito.mock(DocumentQuery.class);
AtomicReference<List<Person>> reference = new AtomicReference<>();
Person ada = Person.builder().withId(1L).withAge(30).withName("Ada").build();
Mockito.when(template.select(query)).thenReturn(Stream.of(ada));
final Observable<Person> observable = manager.select(query);
Mockito.verify(template, Mockito.never()).select(query);
CompletionStage<List<Person>> completion = observable.getList();
completion.thenAccept(reference::set);
Mockito.verify(template).select(query);
MatcherAssert.assertThat(reference.get(), Matchers.containsInAnyOrder(ada));
}
Aggregations