use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldFindByIdReturnEmptyWhenElementDoesNotFind.
@Test
public void shouldFindByIdReturnEmptyWhenElementDoesNotFind() {
ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
AtomicBoolean condition = new AtomicBoolean(false);
AtomicReference<Person> atomicReference = new AtomicReference<>();
Consumer<Optional<Person>> callback = p -> {
condition.set(true);
p.ifPresent(atomicReference::set);
};
subject.find(Person.class, 10L, callback);
verify(managerMock).select(queryCaptor.capture(), dianaCallbackCaptor.capture());
Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
dianaCallBack.accept(emptyList());
ColumnQuery query = queryCaptor.getValue();
assertEquals("Person", query.getColumnFamily());
assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), query.getCondition().get());
assertNull(atomicReference.get());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult.
@Test
public void shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult() {
assertThrows(NonUniqueResultException.class, () -> {
ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
ColumnQuery query = ColumnQueryBuilder.select().from("Person").build();
Consumer<Optional<Person>> callback = l -> {
};
subject.singleResult(query, callback);
verify(managerMock).select(Mockito.any(ColumnQuery.class), dianaCallbackCaptor.capture());
Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
dianaCallBack.accept(asList(ColumnEntity.of("Person", asList(columns)), ColumnEntity.of("Person", asList(columns))));
});
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldReturnSingleResult.
@Test
public void shouldReturnSingleResult() {
ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
ColumnQuery query = ColumnQueryBuilder.select().from("Person").build();
AtomicBoolean condition = new AtomicBoolean(false);
AtomicReference<Person> atomicReference = new AtomicReference<>();
Consumer<Optional<Person>> callback = p -> {
condition.set(true);
p.ifPresent(atomicReference::set);
};
subject.singleResult(query, callback);
verify(managerMock).select(Mockito.any(ColumnQuery.class), dianaCallbackCaptor.capture());
Consumer<List<ColumnEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
dianaCallBack.accept(singletonList(ColumnEntity.of("Person", asList(columns))));
verify(managerMock).select(Mockito.eq(query), Mockito.any());
await().untilTrue(condition);
assertNotNull(atomicReference.get());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateTest method shouldReturnSingleResultIsEmpty.
@Test
public void shouldReturnSingleResultIsEmpty() {
Mockito.when(managerMock.select(any(ColumnQuery.class))).thenReturn(emptyList());
ColumnQuery query = select().from("person").build();
Optional<Person> result = subject.singleResult(query);
assertFalse(result.isPresent());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateTest method shouldSelect.
@Test
public void shouldSelect() {
ColumnQuery query = select().from("person").build();
subject.select(query);
verify(managerMock).select(query);
}
Aggregations