Search in sources :

Example 86 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldRetrieveListDocumentList.

@Test
public void shouldRetrieveListDocumentList() {
    DocumentEntity entity = entityManager.insert(createDocumentList());
    Document key = entity.find(CouchDBConstant.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 : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeReference(jakarta.nosql.TypeReference) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) INSTANCE(org.eclipse.jnosql.communication.couchdb.document.configuration.CouchDBDocumentTcConfiguration.INSTANCE) Document(jakarta.nosql.document.Document) UUID(java.util.UUID) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Collections(java.util.Collections) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 87 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldSaveMap.

@Test
public void shouldSaveMap() {
    DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
    String id = UUID.randomUUID().toString();
    entity.add("properties", Collections.singletonMap("hallo", "Welt"));
    entity.add("scope", "xxx");
    entity.add("_id", id);
    entityManager.insert(entity);
    final DocumentQuery query = select().from(COLLECTION_NAME).where("_id").eq(id).and("scope").eq("xxx").build();
    final Optional<DocumentEntity> optional = entityManager.select(query).findFirst();
    Assertions.assertTrue(optional.isPresent());
    DocumentEntity documentEntity = optional.get();
    Document properties = documentEntity.find("properties").get();
    Assertions.assertNotNull(properties);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 88 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() {
    DocumentEntity entity = getEntity();
    entity.remove(CouchDBConstant.ID);
    entity = entityManager.insert(entity);
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 89 with DocumentEntity

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

the class ElasticsearchEntry method toEntity.

DocumentEntity toEntity() {
    Document id = Document.of(ID_FIELD, this.id);
    List<Document> documents = map.keySet().stream().map(k -> toDocument(k, map)).collect(Collectors.toList());
    DocumentEntity entity = DocumentEntity.of(collection, documents);
    entity.remove(ID_FIELD);
    entity.add(id);
    return entity;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) GetResponse(org.elasticsearch.action.get.GetResponse) ID_FIELD(org.eclipse.jnosql.communication.elasticsearch.document.EntityConverter.ID_FIELD) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ENTITY(org.eclipse.jnosql.communication.elasticsearch.document.EntityConverter.ENTITY) StreamSupport.stream(java.util.stream.StreamSupport.stream) Map(java.util.Map) Objects.isNull(java.util.Objects.isNull) DocumentEntity(jakarta.nosql.document.DocumentEntity) Document(jakarta.nosql.document.Document)

Example 90 with DocumentEntity

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

the class HttpExecute method toEntity.

private DocumentEntity toEntity(Map<String, Object> jsonEntity) {
    DocumentEntity entity = DocumentEntity.of(jsonEntity.get(CouchDBConstant.ENTITY).toString());
    entity.addAll(Documents.of(jsonEntity));
    entity.remove(CouchDBConstant.ENTITY);
    return entity;
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity)

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