use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldSelect.
@Test
public void shouldSelect() {
ArgumentCaptor<Consumer<List<ColumnEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
ColumnQuery query = ColumnQueryBuilder.select().from("Person").build();
AtomicBoolean condition = new AtomicBoolean(false);
Consumer<List<Person>> callback = l -> {
condition.set(true);
};
subject.select(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);
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldFindById.
@Test
public void shouldFindById() {
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(singletonList(ColumnEntity.of("Person", asList(columns))));
ColumnQuery query = queryCaptor.getValue();
assertEquals("Person", query.getColumnFamily());
assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), query.getCondition().get());
assertNotNull(atomicReference.get());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateTest method shouldReturnSingleResult.
@Test
public void shouldReturnSingleResult() {
ColumnEntity columnEntity = ColumnEntity.of("Person");
columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
Mockito.when(managerMock.select(any(ColumnQuery.class))).thenReturn(singletonList(columnEntity));
ColumnQuery query = select().from("person").build();
Optional<Person> result = subject.singleResult(query);
assertTrue(result.isPresent());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateTest method shouldReturnErrorWhenThereMoreThanASingleResult.
@Test
public void shouldReturnErrorWhenThereMoreThanASingleResult() {
Assertions.assertThrows(NonUniqueResultException.class, () -> {
ColumnEntity columnEntity = ColumnEntity.of("Person");
columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
Mockito.when(managerMock.select(any(ColumnQuery.class))).thenReturn(Arrays.asList(columnEntity, columnEntity));
ColumnQuery query = select().from("person").build();
subject.singleResult(query);
});
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateTest method shouldReturnFind.
@Test
public void shouldReturnFind() {
subject.find(Person.class, "10");
ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(managerMock).select(queryCaptor.capture());
ColumnQuery query = queryCaptor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(ColumnCondition.eq(Column.of("_id", 10L)), condition);
}
Aggregations