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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations