Search in sources :

Example 6 with DocumentCollectionManager

use of jakarta.nosql.document.DocumentCollectionManager in project jnosql-diana by eclipse.

the class DefaultDocumentTemplateProducerTest method shouldReturn.

@Test
public void shouldReturn() {
    DocumentCollectionManager manager = Mockito.mock(DocumentCollectionManager.class);
    DocumentTemplate documentTemplate = producer.get(manager);
    assertNotNull(documentTemplate);
}
Also used : DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Test(org.junit.jupiter.api.Test)

Example 7 with DocumentCollectionManager

use of jakarta.nosql.document.DocumentCollectionManager in project jnosql-diana by eclipse.

the class DefaultDocumentRepositoryProducerTest method shouldCreateFromManager.

@Test
public void shouldCreateFromManager() {
    DocumentCollectionManager manager = Mockito.mock(DocumentCollectionManager.class);
    PersonRepository personRepository = producer.get(PersonRepository.class, manager);
    assertNotNull(personRepository);
}
Also used : PersonRepository(jakarta.nosql.tck.entities.PersonRepository) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) Test(org.junit.jupiter.api.Test)

Example 8 with DocumentCollectionManager

use of jakarta.nosql.document.DocumentCollectionManager in project jnosql-diana by eclipse.

the class ManagerProducerProducer method getDocumentCollectionManager.

@Produces
public DocumentCollectionManager getDocumentCollectionManager() {
    DocumentCollectionManager collectionManager = Mockito.mock(DocumentCollectionManager.class);
    DocumentEntity entity = DocumentEntity.of("person");
    entity.add(Document.of("name", "Ada"));
    entity.add(Document.of("age", 10));
    entity.add(Document.of("salary", BigDecimal.TEN));
    entity.add(Document.of("phones", singletonList("22342342")));
    when(collectionManager.insert(Mockito.any(DocumentEntity.class))).thenReturn(entity);
    when(collectionManager.update(Mockito.any(DocumentEntity.class))).thenReturn(entity);
    return collectionManager;
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) Produces(javax.enterprise.inject.Produces)

Example 9 with DocumentCollectionManager

use of jakarta.nosql.document.DocumentCollectionManager in project jnosql-diana by eclipse.

the class DefaultDeleteQueryBuilderTest method shouldExecuteDelete.

@Test
public void shouldExecuteDelete() {
    String collection = "collection";
    DocumentCollectionManager manager = mock(DocumentCollectionManager.class);
    ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    delete().from(collection).delete(manager);
    verify(manager).delete(queryCaptor.capture());
    DocumentDeleteQuery query = queryCaptor.getValue();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(collection, query.getDocumentCollection());
}
Also used : DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 10 with DocumentCollectionManager

use of jakarta.nosql.document.DocumentCollectionManager in project jnosql-diana by eclipse.

the class DocumentPageTest method setUp.

@BeforeEach
public void setUp() {
    managerMock = Mockito.mock(DocumentCollectionManager.class);
    columnEventPersistManager = Mockito.mock(DocumentEventPersistManager.class);
    captor = ArgumentCaptor.forClass(DocumentEntity.class);
    Instance<DocumentCollectionManager> instance = Mockito.mock(Instance.class);
    when(instance.get()).thenReturn(managerMock);
    this.subject = new DefaultDocumentTemplate(converter, instance, new DefaultDocumentWorkflow(columnEventPersistManager, converter), columnEventPersistManager, classMappings, converters);
    Pagination pagination = Pagination.page(1).size(1);
    DocumentQueryPagination query = DocumentQueryPagination.of(select().from("person").build(), pagination);
    for (int index = 0; index <= 10; index++) {
        Document[] columns = new Document[] { Document.of("age", index), Document.of("name", "Ada " + index), Document.of("_id", (long) index) };
        DocumentEntity columnEntity = DocumentEntity.of("Person");
        columnEntity.addAll(Stream.of(columns).collect(Collectors.toList()));
        when(managerMock.select(query)).thenReturn(Stream.of(columnEntity));
        query = query.next();
    }
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentEventPersistManager(jakarta.nosql.mapping.document.DocumentEventPersistManager) DocumentQueryPagination(jakarta.nosql.mapping.document.DocumentQueryPagination) Document(jakarta.nosql.document.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)17 DocumentEntity (jakarta.nosql.document.DocumentEntity)8 Test (org.junit.jupiter.api.Test)8 Produces (javax.enterprise.inject.Produces)5 DocumentQuery (jakarta.nosql.document.DocumentQuery)4 DocumentTemplateProducer (jakarta.nosql.mapping.document.DocumentTemplateProducer)3 Database (jakarta.nosql.mapping.Database)2 Document (jakarta.nosql.document.Document)1 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)1 Pagination (jakarta.nosql.mapping.Pagination)1 DocumentEventPersistManager (jakarta.nosql.mapping.document.DocumentEventPersistManager)1 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)1 DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)1 PersonRepository (jakarta.nosql.tck.entities.PersonRepository)1 DocumentCollectionManagerMock (org.eclipse.jnosql.mapping.document.configuration.DocumentConfigurationMock.DocumentCollectionManagerMock)1 Config (org.eclipse.microprofile.config.Config)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1