Search in sources :

Example 71 with DocumentEntity

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

the class CouchbaseDocumentCollectionManagerTest method shouldRunN1QlParameters.

@Test
public void shouldRunN1QlParameters() {
    DocumentEntity entity = getEntity();
    entityManager.insert(entity);
    JsonObject params = JsonObject.create().put("name", "Poliana");
    List<DocumentEntity> entities = entityManager.n1qlQuery("select * from jnosql where name = $name", params).collect(Collectors.toList());
    assertFalse(entities.isEmpty());
    assertEquals(1, entities.size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) JsonObject(com.couchbase.client.java.document.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 72 with DocumentEntity

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

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

the class CouchbaseDocumentCollectionManagerTest method shouldRunN1QlStatement.

@Test
public void shouldRunN1QlStatement() {
    DocumentEntity entity = getEntity();
    entityManager.insert(entity);
    Statement statement = Select.select("*").from("jnosql").where(x("name").eq("\"Poliana\""));
    List<DocumentEntity> entities = entityManager.n1qlQuery(statement).collect(Collectors.toList());
    assertFalse(entities.isEmpty());
    assertEquals(1, entities.size());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) Statement(com.couchbase.client.java.query.Statement) Test(org.junit.jupiter.api.Test)

Example 74 with DocumentEntity

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

Example 75 with DocumentEntity

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

the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.

@Test
public void shouldRemoveEntityByName() {
    DocumentEntity documentEntity = entityManager.insert(getEntity());
    Document name = documentEntity.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)

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