Search in sources :

Example 66 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity 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 67 with DocumentEntity

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

the class ArangoDBDocumentCollectionManagerTest method shouldReadFromDifferentBaseDocumentUsingInstance.

@Test
public void shouldReadFromDifferentBaseDocumentUsingInstance() {
    entityManager.insert(getEntity());
    ArangoDB arangoDB = DefaultArangoDBDocumentCollectionManager.class.cast(entityManager).getArangoDB();
    arangoDB.db(DATABASE).collection(COLLECTION_NAME).insertDocument(new Person());
    DocumentQuery select = select().from(COLLECTION_NAME).build();
    List<DocumentEntity> entities = entityManager.select(select).collect(Collectors.toList());
    assertFalse(entities.isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) ArangoDB(com.arangodb.ArangoDB) DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 68 with DocumentEntity

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

the class CouchbaseDocumentCollectionManagerTest method shouldRunN1Ql.

@Test
public void shouldRunN1Ql() {
    DocumentEntity entity = getEntity();
    entityManager.insert(entity);
    List<DocumentEntity> entities = entityManager.n1qlQuery("select * from jnosql").collect(Collectors.toList());
    assertFalse(entities.isEmpty());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 69 with DocumentEntity

use of jakarta.nosql.document.DocumentEntity 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 70 with DocumentEntity

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

the class CouchbaseDocumentCollectionManagerTest method createSubdocumentList.

private DocumentEntity createSubdocumentList() {
    DocumentEntity entity = DocumentEntity.of("AppointmentBook");
    entity.add(Document.of("_id", "ids"));
    List<List<Document>> documents = new ArrayList<>();
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.EMAIL), Document.of("information", "ada@lovelace.com")));
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.MOBILE), Document.of("information", "11 1231231 123")));
    documents.add(asList(Document.of("name", "Ada"), Document.of("type", ContactType.PHONE), Document.of("information", "phone")));
    entity.add(Document.of("contacts", documents));
    return entity;
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

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