Search in sources :

Example 81 with Document

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

the class MongoDBDocumentCollectionManagerTest method shouldFindDocument2.

@Test
public void shouldFindDocument2() {
    DocumentEntity entity = entityManager.insert(getEntity());
    Optional<Document> id = entity.find("_id");
    DocumentQuery query = select().from(COLLECTION_NAME).where("name").eq("Poliana").and("city").eq("Salvador").and("_id").eq(id.get().get()).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertFalse(entities.isEmpty());
    assertThat(entities, contains(entity));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 82 with Document

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

the class MongoDBDocumentCollectionManagerTest method getEntity.

private DocumentEntity getEntity() {
    DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
    Map<String, Object> map = new HashMap<>();
    map.put("name", "Poliana");
    map.put("city", "Salvador");
    List<Document> documents = Documents.of(map);
    documents.forEach(entity::add);
    return entity;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashMap(java.util.HashMap) Document(org.jnosql.diana.api.document.Document)

Example 83 with Document

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

the class MongoDBDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find("_id").get();
    DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
    DocumentEntity documentEntity = entityManager.singleResult(query).get();
    assertNotNull(documentEntity);
    List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
    assertEquals(3, contacts.size());
    assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Also used : Document(org.jnosql.diana.api.document.Document) TypeReference(org.jnosql.diana.api.TypeReference) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) IOException(java.io.IOException) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) DocumentCollectionManager(org.jnosql.diana.api.document.DocumentCollectionManager) Documents(org.jnosql.diana.api.document.Documents) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) DocumentConfigurationUtils.get(org.jnosql.diana.mongodb.document.DocumentConfigurationUtils.get) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 84 with Document

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

the class MongoDBDocumentCollectionManagerTest method shouldInsert.

@Test
public void shouldInsert() {
    DocumentEntity entity = getEntity();
    DocumentEntity documentEntity = entityManager.insert(entity);
    assertTrue(documentEntity.getDocuments().stream().map(Document::getName).anyMatch(s -> s.equals("_id")));
}
Also used : Document(org.jnosql.diana.api.document.Document) TypeReference(org.jnosql.diana.api.TypeReference) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) Random(java.util.Random) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) IOException(java.io.IOException) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) DocumentCollectionManager(org.jnosql.diana.api.document.DocumentCollectionManager) Documents(org.jnosql.diana.api.document.Documents) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) DocumentConfigurationUtils.get(org.jnosql.diana.mongodb.document.DocumentConfigurationUtils.get) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 85 with Document

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

the class MongoDBDocumentCollectionManagerTest method shouldUpdateSave.

@Test
public void shouldUpdateSave() {
    DocumentEntity entity = getEntity();
    DocumentEntity documentEntity = entityManager.insert(entity);
    Document newField = Documents.of("newField", "10");
    entity.add(newField);
    DocumentEntity updated = entityManager.update(entity);
    assertEquals(newField, updated.find("newField").get());
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8