Search in sources :

Example 51 with DocumentEntity

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;
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) DocumentEntity(jakarta.nosql.document.DocumentEntity)

Example 52 with DocumentEntity

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;
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) Produces(javax.enterprise.inject.Produces)

Example 53 with DocumentEntity

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;
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) Produces(javax.enterprise.inject.Produces) Database(jakarta.nosql.mapping.Database)

Example 54 with DocumentEntity

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());
}
Also used : DocumentEntityPostPersist(jakarta.nosql.mapping.document.DocumentEntityPostPersist) DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 55 with DocumentEntity

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());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentEntityPrePersist(jakarta.nosql.mapping.document.DocumentEntityPrePersist) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (jakarta.nosql.document.DocumentEntity)312 Test (org.junit.jupiter.api.Test)238 DocumentQuery (jakarta.nosql.document.DocumentQuery)131 Document (jakarta.nosql.document.Document)129 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)62 List (java.util.List)54 Arrays.asList (java.util.Arrays.asList)51 ArrayList (java.util.ArrayList)46 Duration (java.time.Duration)31 HashMap (java.util.HashMap)30 Map (java.util.Map)27 Collectors (java.util.stream.Collectors)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)25 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 ValueSource (org.junit.jupiter.params.provider.ValueSource)23 TypeReference (jakarta.nosql.TypeReference)21 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)21 Matchers.contains (org.hamcrest.Matchers.contains)21 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)21