Search in sources :

Example 91 with DocumentEntity

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

the class DefaultDocumentTemplateTest method shouldInsertEntitiesTTL.

@Test
public void shouldInsertEntitiesTTL() {
    DocumentEntity documentEntity = DocumentEntity.of("Person");
    documentEntity.addAll(Stream.of(documents).collect(Collectors.toList()));
    Duration duration = Duration.ofHours(2);
    Mockito.when(managerMock.insert(any(DocumentEntity.class), Mockito.eq(duration))).thenReturn(documentEntity);
    subject.insert(Arrays.asList(person, person), duration);
    verify(managerMock, times(2)).insert(any(DocumentEntity.class), any(Duration.class));
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Duration(java.time.Duration) Test(org.junit.jupiter.api.Test)

Example 92 with DocumentEntity

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

the class DefaultDocumentEntityConverterTest method shouldConvertToEntityWhenHasConverter.

@Test
public void shouldConvertToEntityWhenHasConverter() {
    Worker worker = new Worker();
    Job job = new Job();
    job.setCity("Sao Paulo");
    job.setDescription("Java Developer");
    worker.setName("Bob");
    worker.setSalary(new Money("BRL", BigDecimal.TEN));
    worker.setJob(job);
    DocumentEntity entity = converter.toDocument(worker);
    Worker worker1 = converter.toEntity(entity);
    assertEquals(worker.getSalary(), worker1.getSalary());
    assertEquals(job.getCity(), worker1.getJob().getCity());
    assertEquals(job.getDescription(), worker1.getJob().getDescription());
}
Also used : Money(org.jnosql.artemis.model.Money) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Worker(org.jnosql.artemis.model.Worker) Job(org.jnosql.artemis.model.Job) Test(org.junit.jupiter.api.Test)

Example 93 with DocumentEntity

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

the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsyncWithNativeQueryMapParam.

@Test
public void shouldFindAsyncWithNativeQueryMapParam() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Optional<Document> id = entity.find(OrientDBConverter.RID_FIELD);
    Optional<Document> name = entity.find("name");
    AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
    Map<String, Object> params = new HashMap<>();
    params.put("id", id.get().get());
    params.put("name", name.get().get());
    entityManagerAsync.sql("select * from person where @rid = :id and name = :name", reference::set, params);
    await().until(reference::get, notNullValue(List.class));
    assertFalse(reference.get().isEmpty());
    assertEquals(reference.get().get(0), entity);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 94 with DocumentEntity

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

the class OrientDBDocumentCollectionManagerAsyncTest method shouldFindAsyncWithNativeQuery.

@Test
public void shouldFindAsyncWithNativeQuery() {
    DocumentEntity entity = entityManager.insert(getEntity());
    AtomicReference<List<DocumentEntity>> reference = new AtomicReference<>();
    StringBuilder query = new StringBuilder().append("SELECT FROM ").append(COLLECTION_NAME).append(" WHERE name = ?");
    entityManagerAsync.sql(query.toString(), reference::set, "Poliana");
    await().until(reference::get, notNullValue(List.class));
    assertFalse(reference.get().isEmpty());
    assertEquals(reference.get().get(0), entity);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 95 with DocumentEntity

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

the class OrientDBDocumentCollectionManagerTest method getEntities.

private List<DocumentEntity> getEntities() {
    DocumentEntity otavio = DocumentEntity.of(COLLECTION_NAME);
    otavio.add(Document.of("name", "Otavio"));
    otavio.add(Document.of("city", "Sao Paulo"));
    DocumentEntity lucas = DocumentEntity.of(COLLECTION_NAME);
    lucas.add(Document.of("name", "Lucas"));
    lucas.add(Document.of("city", "Assis"));
    return asList(getEntity(), otavio, lucas);
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity)

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