Search in sources :

Example 51 with Document

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

the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity.

@Test
public void shouldRemoveEntity() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("_key").get();
    DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(select).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 52 with Document

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

the class ArangoDBDocumentCollectionManagerTest method shouldRemoveEntity2.

@Test
public void shouldRemoveEntity2() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document id = documentEntity.find("name").get();
    DocumentQuery select = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    entityManager.delete(deleteQuery);
    assertTrue(entityManager.select(select).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 53 with Document

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

the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument.

@Test
public void shouldSaveSubDocument() throws InterruptedException {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Document.of("mobile", "1231231")));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Thread.sleep(5_00L);
    Document id = entitySaved.find("_id").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, contains(Document.of("mobile", "1231231")));
}
Also used : 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 54 with Document

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

the class CouchbaseDocumentCollectionManagerTest 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 : Expression.x(com.couchbase.client.java.query.dsl.Expression.x) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) Statement(com.couchbase.client.java.query.Statement) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) JsonObject(com.couchbase.client.java.document.json.JsonObject) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) Select(com.couchbase.client.java.query.Select) TypeReference(jakarta.nosql.TypeReference) CouchbaseDocumentTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseDocumentTcConfiguration) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CouchbaseKeyValueConfiguration(org.eclipse.jnosql.communication.couchbase.keyvalue.CouchbaseKeyValueConfiguration) BucketManager(jakarta.nosql.keyvalue.BucketManager) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) BucketManagerFactory(jakarta.nosql.keyvalue.BucketManagerFactory) Set(java.util.Set) CouchbaseUtil(org.eclipse.jnosql.communication.couchbase.CouchbaseUtil) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CouchbaseKeyValueTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseKeyValueTcConfiguration) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) 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 55 with Document

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

the class CouchbaseDocumentCollectionManagerTest 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");
    map.put("_id", "id");
    List<Document> documents = Documents.of(map);
    documents.forEach(entity::add);
    return entity;
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) HashMap(java.util.HashMap) JsonObject(com.couchbase.client.java.document.json.JsonObject) Document(jakarta.nosql.document.Document)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14