use of org.jnosql.diana.api.document.DocumentEntity 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.diana.api.document.DocumentEntity 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());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateAsyncTest method shouldReturnErrorFindByIdReturnMoreThanOne.
@Test
public void shouldReturnErrorFindByIdReturnMoreThanOne() {
assertThrows(NonUniqueResultException.class, () -> {
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(asList(DocumentEntity.of("Person", asList(documents)), DocumentEntity.of("Person", asList(documents))));
});
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateTest method shouldSave.
@Test
public void shouldSave() {
DocumentEntity document = DocumentEntity.of("Person");
document.addAll(Stream.of(documents).collect(Collectors.toList()));
when(managerMock.insert(any(DocumentEntity.class))).thenReturn(document);
subject.insert(this.person);
verify(managerMock).insert(captor.capture());
verify(documentEventPersistManager).firePostEntity(any(Person.class));
verify(documentEventPersistManager).firePreEntity(any(Person.class));
verify(documentEventPersistManager).firePreDocument(any(DocumentEntity.class));
verify(documentEventPersistManager).firePostDocument(any(DocumentEntity.class));
DocumentEntity value = captor.getValue();
assertEquals("Person", value.getName());
assertEquals(4, value.getDocuments().size());
}
use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.
the class DefaultDocumentTemplateTest method shouldInsertEntities.
@Test
public void shouldInsertEntities() {
DocumentEntity documentEntity = DocumentEntity.of("Person");
documentEntity.addAll(Stream.of(documents).collect(Collectors.toList()));
Mockito.when(managerMock.insert(any(DocumentEntity.class))).thenReturn(documentEntity);
subject.insert(Arrays.asList(person, person));
verify(managerMock, times(2)).insert(any(DocumentEntity.class));
}
Aggregations