use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class AbstractColumnEntityConverter method toColumn.
@Override
public ColumnEntity toColumn(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
ColumnEntity entity = ColumnEntity.of(representation.getName());
representation.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toColumn(this, getConverters())).flatMap(List::stream).forEach(entity::add);
return entity;
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldReturnErrorFindByIdReturnMoreThanOne.
@Test
public void shouldReturnErrorFindByIdReturnMoreThanOne() {
assertThrows(NonUniqueResultException.class, () -> {
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(asList(ColumnEntity.of("Person", asList(columns)), ColumnEntity.of("Person", asList(columns))));
});
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldReturnEmptySingleResult.
@Test
public void shouldReturnEmptySingleResult() {
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(emptyList());
verify(managerMock).select(Mockito.eq(query), Mockito.any());
await().untilTrue(condition);
assertNull(atomicReference.get());
}
use of org.jnosql.diana.api.column.ColumnEntity 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.ColumnEntity in project jnosql-artemis by eclipse.
the class DefaultColumnTemplateAsyncTest method shouldInsertIterableTTL.
@Test
public void shouldInsertIterableTTL() {
ColumnEntity entity = ColumnEntity.of("Person");
entity.addAll(Stream.of(columns).collect(Collectors.toList()));
subject.insert(singletonList(this.person), Duration.ofSeconds(1L));
verify(managerMock).insert(Mockito.any(ColumnEntity.class), Mockito.eq(Duration.ofSeconds(1L)), Mockito.any(Consumer.class));
}
Aggregations