Search in sources :

Example 81 with DocumentEntity

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

the class DocumentQueryTest method beforeClass.

@BeforeAll
public static void beforeClass() throws InterruptedException {
    configuration = CouchbaseDocumentTcConfiguration.getTcConfiguration();
    CouhbaseDocumentCollectionManagerFactory managerFactory = configuration.get();
    CouchbaseDocumentCollectionManager entityManager = managerFactory.get(CouchbaseUtil.BUCKET_NAME);
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    DocumentEntity entity2 = DocumentEntity.of("person", asList(Document.of("_id", "id2"), Document.of("name", "name")));
    DocumentEntity entity3 = DocumentEntity.of("person", asList(Document.of("_id", "id3"), Document.of("name", "name")));
    DocumentEntity entity4 = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3")));
    entityManager.insert(Arrays.asList(entity, entity2, entity3, entity4));
    Thread.sleep(2_000L);
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 82 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldSelectEmptyResult.

@Test
public void shouldSelectEmptyResult() {
    DocumentQuery query = select().from(COLLECTION_NAME).where("no_field").eq("not_found").build();
    List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
    assertTrue(entities.isEmpty());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Test(org.junit.jupiter.api.Test)

Example 83 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest 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(CouchDBConstant.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) Document(jakarta.nosql.document.Document)

Example 84 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    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, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "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 85 with DocumentEntity

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

the class DefaultCouchDBDocumentCollectionManagerTest method shouldInsert.

@Test
public void shouldInsert() {
    DocumentEntity entity = getEntity();
    DocumentEntity documentEntity = entityManager.insert(entity);
    assertEquals(entity, documentEntity);
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) 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