Search in sources :

Example 81 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.

the class DefaultDocumentEntityConverterTest method shouldConvertDocumentEntityFromEntity.

@Test
public void shouldConvertDocumentEntityFromEntity() {
    Person person = Person.builder().withAge().withId(12).withName("Otavio").withPhones(Arrays.asList("234", "2342")).build();
    DocumentEntity entity = converter.toDocument(person);
    assertEquals("Person", entity.getName());
    assertEquals(4, entity.size());
    assertThat(entity.getDocuments(), containsInAnyOrder(Document.of("_id", 12L), Document.of("age", 10), Document.of("name", "Otavio"), Document.of("phones", Arrays.asList("234", "2342"))));
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 82 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis 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(org.jnosql.diana.api.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 83 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.

the class DefaultDocumentTemplateAsyncTest method shouldInsertTTL.

@Test
public void shouldInsertTTL() {
    Duration twoHours = Duration.ofHours(2L);
    DocumentEntity entity = DocumentEntity.of("Person");
    entity.addAll(Stream.of(documents).collect(Collectors.toList()));
    subject.insert(this.person, twoHours);
    verify(managerMock).insert(captor.capture(), Mockito.eq(twoHours), Mockito.any(Consumer.class));
    DocumentEntity value = captor.getValue();
    assertEquals("Person", value.getName());
    assertEquals(4, value.getDocuments().size());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 84 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.

the class DefaultDocumentTemplateAsyncTest method shouldUpdate.

@Test
public void shouldUpdate() {
    DocumentEntity entity = DocumentEntity.of("Person");
    entity.addAll(Stream.of(documents).collect(Collectors.toList()));
    subject.update(this.person);
    verify(managerMock).update(captor.capture(), Mockito.any(Consumer.class));
    DocumentEntity value = captor.getValue();
    assertEquals("Person", value.getName());
    assertEquals(4, value.getDocuments().size());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test)

Example 85 with DocumentEntity

use of org.jnosql.diana.api.document.DocumentEntity in project jnosql-artemis by eclipse.

the class DefaultDocumentTemplateAsyncTest method shouldUpdateIterable.

@Test
public void shouldUpdateIterable() {
    DocumentEntity entity = DocumentEntity.of("Person");
    entity.addAll(Stream.of(documents).collect(Collectors.toList()));
    subject.update(singletonList(this.person));
    verify(managerMock).update(captor.capture(), Mockito.any(Consumer.class));
    DocumentEntity value = captor.getValue();
    assertEquals(entity.getName(), value.getName());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)205 Test (org.junit.jupiter.api.Test)167 Document (org.jnosql.diana.api.document.Document)107 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)101 List (java.util.List)63 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)47 Arrays.asList (java.util.Arrays.asList)38 ArrayList (java.util.ArrayList)36 AtomicReference (java.util.concurrent.atomic.AtomicReference)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25 Duration (java.time.Duration)22 HashMap (java.util.HashMap)21 Consumer (java.util.function.Consumer)19 Arrays (java.util.Arrays)17 Collectors (java.util.stream.Collectors)17 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)17 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Map (java.util.Map)15 Optional (java.util.Optional)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15