use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DeleteQueryParserTest method shouldReturnParserQuery23.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where name = \"Ada\" and age = 20" })
public void shouldReturnParserQuery23(String query) {
ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
parser.query(query, documentCollection, observer);
Mockito.verify(documentCollection).delete(captor.capture());
DocumentDeleteQuery documentQuery = captor.getValue();
checkBaseQuery(documentQuery);
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>>() {
});
assertThat(conditions, contains(eq(Document.of("name", "Ada")), eq(Document.of("age", 20L))));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class AbstractMapperQuery method likeImpl.
protected void likeImpl(String value) {
requireNonNull(value, "value is required");
DocumentCondition newCondition = DocumentCondition.like(Document.of(mapping.getColumnField(name), getValue(value)));
appendCondition(newCondition);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class AbstractMapperQuery method gtImpl.
protected <T> void gtImpl(T value) {
requireNonNull(value, "value is required");
DocumentCondition newCondition = DocumentCondition.gt(Document.of(mapping.getColumnField(name), getValue(value)));
appendCondition(newCondition);
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameInstance.
@Test
public void shouldFindByNameInstance() {
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.of(Person.builder().build()));
personRepository.findByName("name");
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).singleResult(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Document.of("name", "name"), condition.getDocument());
assertNotNull(personRepository.findByName("name"));
when(template.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
assertNull(personRepository.findByName("name"));
}
use of jakarta.nosql.document.DocumentCondition in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest method shouldFindByNameAndAgeGreaterEqualThan.
@Test
public void shouldFindByNameAndAgeGreaterEqualThan() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
personRepository.findByNameAndAgeGreaterThanEqual("Ada", 33);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(AND, condition.getCondition());
List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
DocumentCondition columnCondition = conditions.get(0);
DocumentCondition columnCondition2 = conditions.get(1);
assertEquals(Condition.EQUALS, columnCondition.getCondition());
assertEquals("Ada", columnCondition.getDocument().get());
assertTrue(columnCondition.getDocument().getName().contains("name"));
assertEquals(Condition.GREATER_EQUALS_THAN, columnCondition2.getCondition());
assertEquals(33, columnCondition2.getDocument().get());
assertTrue(columnCondition2.getDocument().getName().contains("age"));
}
Aggregations