Search in sources :

Example 56 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldInsert.

@Test
public void shouldInsert() {
    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());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 57 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldSaveTTL.

@Test
public void shouldSaveTTL() {
    Duration twoHours = Duration.ofHours(2L);
    DocumentEntity document = DocumentEntity.of("Person");
    document.addAll(Stream.of(documents).collect(Collectors.toList()));
    when(managerMock.insert(any(DocumentEntity.class), Mockito.eq(twoHours))).thenReturn(document);
    subject.insert(this.person, twoHours);
    verify(managerMock).insert(captor.capture(), Mockito.eq(twoHours));
    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());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Duration(java.time.Duration) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 58 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldMergeOnUpdate.

@Test
public void shouldMergeOnUpdate() {
    DocumentEntity document = DocumentEntity.of("Person");
    document.addAll(Stream.of(documents).collect(Collectors.toList()));
    when(managerMock.update(any(DocumentEntity.class))).thenReturn(document);
    Person person = Person.builder().build();
    Person result = subject.update(person);
    verify(managerMock).update(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();
    assertSame(person, result);
    assertEquals(10, person.getAge());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 59 with DocumentEntity

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

the class DocumentEntityPrePersistTest method shouldReturnInstance.

@Test
public void shouldReturnInstance() {
    DocumentEntity entity = DocumentEntity.of("collection");
    DocumentEntityPrePersist prePersist = new DefaultDocumentEntityPrePersist(entity);
    assertEquals(entity, prePersist.getEntity());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentEntityPrePersist(jakarta.nosql.mapping.document.DocumentEntityPrePersist) Test(org.junit.jupiter.api.Test)

Example 60 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity 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)

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