use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class AbstractDocumentEntityConverter method toDocument.
@Override
public DocumentEntity toDocument(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassMapping mapping = getClassMappings().get(entityInstance.getClass());
DocumentEntity entity = DocumentEntity.of(mapping.getName());
mapping.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toDocument(this, getConverters())).flatMap(List::stream).forEach(entity::add);
return entity;
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class MockProducer method getDocumentCollectionManager.
@Produces
public DocumentCollectionManager getDocumentCollectionManager() {
DocumentEntity entity = DocumentEntity.of("Person");
entity.add(Document.of("name", "Default"));
entity.add(Document.of("age", 10));
DocumentCollectionManager manager = mock(DocumentCollectionManager.class);
when(manager.insert(Mockito.any(DocumentEntity.class))).thenReturn(entity);
return manager;
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class MockProducer method getDocumentCollectionManagerMock.
@Produces
@Database(value = DatabaseType.DOCUMENT, provider = "documentRepositoryMock")
public DocumentCollectionManager getDocumentCollectionManagerMock() {
DocumentEntity entity = DocumentEntity.of("Person");
entity.add(Document.of("name", "documentRepositoryMock"));
entity.add(Document.of("age", 10));
DocumentCollectionManager manager = mock(DocumentCollectionManager.class);
when(manager.insert(Mockito.any(DocumentEntity.class))).thenReturn(entity);
when(manager.singleResult(Mockito.any(DocumentQuery.class))).thenReturn(Optional.empty());
return manager;
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEventPersistManagerTest method shouldFirePostDocument.
@Test
public void shouldFirePostDocument() {
DocumentEntity entity = DocumentEntity.of("collection");
subject.firePostDocument(entity);
ArgumentCaptor<DocumentEntityPostPersist> captor = ArgumentCaptor.forClass(DocumentEntityPostPersist.class);
verify(documentEntityPostPersistEvent).fire(captor.capture());
DocumentEntityPostPersist captorValue = captor.getValue();
assertEquals(entity, captorValue.getEntity());
}
use of jakarta.nosql.document.DocumentEntity in project jnosql-diana by eclipse.
the class DefaultDocumentEventPersistManagerTest method shouldFirePreDocument.
@Test
public void shouldFirePreDocument() {
DocumentEntity entity = DocumentEntity.of("collection");
subject.firePreDocument(entity);
ArgumentCaptor<DocumentEntityPrePersist> captor = ArgumentCaptor.forClass(DocumentEntityPrePersist.class);
verify(documentEntityPrePersistEvent).fire(captor.capture());
DocumentEntityPrePersist captorValue = captor.getValue();
assertEquals(entity, captorValue.getEntity());
}
Aggregations