Search in sources :

Example 31 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class DefaultDocumentTemplateAsyncTest method shouldDeleteCallBack.

@Test
public void shouldDeleteCallBack() {
    DocumentDeleteQuery query = delete().from("delete").build();
    Consumer<Void> callback = v -> {
    };
    subject.delete(query, callback);
    verify(managerMock).delete(query, callback);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Instance(javax.enterprise.inject.Instance) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Optional(java.util.Optional) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 32 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class DefaultDocumentTemplateAsyncTest method shouldDeleteByEntityCallBack.

@Test
public void shouldDeleteByEntityCallBack() {
    Consumer<Void> callback = v -> {
    };
    subject.delete(Person.class, 10L, callback);
    ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    verify(managerMock).delete(queryCaptor.capture(), Mockito.eq(callback));
    DocumentDeleteQuery query = queryCaptor.getValue();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), query.getCondition().get());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) Converters(org.jnosql.artemis.Converters) DocumentCollectionManagerAsync(org.jnosql.diana.api.document.DocumentCollectionManagerAsync) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) NonUniqueResultException(org.jnosql.diana.api.NonUniqueResultException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Instance(javax.enterprise.inject.Instance) Awaitility.await(org.awaitility.Awaitility.await) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Collectors(java.util.stream.Collectors) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Optional(java.util.Optional) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 33 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplate method delete.

@Override
public <T, ID> void delete(Class<T> entityClass, ID id) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
    FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
    DocumentDeleteQuery query = DocumentQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    delete(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Example 34 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplateAsync method delete.

@Override
public <T, ID> void delete(Class<T> entityClass, ID id, Consumer<Void> callBack) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    requireNonNull(callBack, "callBack is required");
    DocumentDeleteQuery query = getDeleteQuery(entityClass, id);
    delete(query, callBack);
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Example 35 with DocumentDeleteQuery

use of org.jnosql.diana.api.document.DocumentDeleteQuery in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplateAsync method delete.

@Override
public <T, ID> void delete(Class<T> entityClass, ID id) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    DocumentDeleteQuery query = getDeleteQuery(entityClass, id);
    delete(query);
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Aggregations

DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)86 Test (org.junit.jupiter.api.Test)74 Document (org.jnosql.diana.api.document.Document)35 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)31 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)20 List (java.util.List)15 Person (org.jnosql.artemis.model.Person)13 Duration (java.time.Duration)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Optional (java.util.Optional)4 Consumer (java.util.function.Consumer)4 Collectors (java.util.stream.Collectors)4 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)4 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)4 Arrays (java.util.Arrays)3