use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DefaultColumnMapperSelectBuilderTest method shouldSelectWhereNameEq.
@Test
public void shouldSelectWhereNameEq() {
ColumnQuery query = mapperBuilder.selectFrom(Person.class).where("name").eq("Ada").build();
ColumnQuery queryExpected = select().from("Person").where("name").eq("Ada").build();
assertEquals(queryExpected, query);
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity.
@Test
public void shouldConvertDocumentEntityFromEntity() {
Person person = Person.builder().withAge().withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).build();
DocumentEntity entity = converter.toDocument(person);
assertEquals("Person", entity.getName());
assertEquals(4, entity.size());
assertThat(entity.getDocuments(), containsInAnyOrder(Document.of("_id", 12L), Document.of("age", 10), Document.of("name", "Otavio"), Document.of("phones", Arrays.asList("234", "2342"))));
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateAsyncTest method shouldDeleteByEntityCallBack.
@Test
public void shouldDeleteByEntityCallBack() {
Consumer<Void> callback = v -> {
};
subject.delete(Person.class, 10L, callback);
ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
verify(managerMock).delete(queryCaptor.capture(), Mockito.eq(callback));
DocumentDeleteQuery query = queryCaptor.getValue();
assertEquals("Person", query.getDocumentCollection());
assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), query.getCondition().get());
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateAsyncTest method shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult.
@Test
public void shouldReturnErrorWhenThereIsMoreThanOneResultInSingleResult() {
assertThrows(NonUniqueResultException.class, () -> {
ArgumentCaptor<Consumer<List<DocumentEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
DocumentQuery query = select().from("Person").build();
Consumer<Optional<Person>> callback = l -> {
};
subject.singleResult(query, callback);
verify(managerMock).select(Mockito.any(DocumentQuery.class), dianaCallbackCaptor.capture());
Consumer<List<DocumentEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
dianaCallBack.accept(asList(DocumentEntity.of("Person", asList(documents)), DocumentEntity.of("Person", asList(documents))));
});
}
use of org.jnosql.artemis.model.Person in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateAsyncTest method shouldFindByIdReturnEmptyWhenElementDoesNotFind.
@Test
public void shouldFindByIdReturnEmptyWhenElementDoesNotFind() {
ArgumentCaptor<Consumer<List<DocumentEntity>>> dianaCallbackCaptor = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.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<DocumentEntity>> dianaCallBack = dianaCallbackCaptor.getValue();
dianaCallBack.accept(emptyList());
DocumentQuery query = queryCaptor.getValue();
assertEquals("Person", query.getDocumentCollection());
assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), query.getCondition().get());
assertNull(atomicReference.get());
}
Aggregations