Search in sources :

Example 41 with DocumentDeleteQuery

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

the class DocumentQueryDeleteParserTest method shouldDeleteByNameAndAge.

@Test
public void shouldDeleteByNameAndAge() {
    DocumentDeleteQuery query = parser.parse("deleteByNameAndAge", new Object[] { "name", 10 }, classRepresentation, converters);
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition condition1 = conditions.get(0);
    assertEquals(Condition.EQUALS, condition1.getCondition());
    assertEquals(Document.of("name", "name"), condition1.getDocument());
    DocumentCondition condition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, condition2.getCondition());
    assertEquals(Document.of("age", 10), condition2.getDocument());
}
Also used : List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 42 with DocumentDeleteQuery

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

the class DocumentQueryDeleteParserTest method shouldDeleteByAgeLessThanEqual.

@Test
public void shouldDeleteByAgeLessThanEqual() {
    DocumentDeleteQuery query = parser.parse("deleteByAgeLessThanEqual", new Object[] { 10 }, classRepresentation, converters);
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.LESSER_EQUALS_THAN, query.getCondition().get().getCondition());
    assertEquals(Document.of("age", 10), query.getCondition().get().getDocument());
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 43 with DocumentDeleteQuery

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

the class DocumentQueryDeleteParserTest method shouldDeleteByAgeGreaterThan.

@Test
public void shouldDeleteByAgeGreaterThan() {
    DocumentDeleteQuery query = parser.parse("deleteByAgeGreaterThan", new Object[] { 10 }, classRepresentation, converters);
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.GREATER_THAN, query.getCondition().get().getCondition());
    assertEquals(Document.of("age", 10), query.getCondition().get().getDocument());
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 44 with DocumentDeleteQuery

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

the class DocumentQueryDeleteParserTest method shouldDeleteByAgeLessThan.

@Test
public void shouldDeleteByAgeLessThan() {
    DocumentDeleteQuery query = parser.parse("deleteByAgeLessThan", new Object[] { 10 }, classRepresentation, converters);
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.LESSER_THAN, query.getCondition().get().getCondition());
    assertEquals(Document.of("age", 10), query.getCondition().get().getDocument());
}
Also used : DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 45 with DocumentDeleteQuery

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

the class DocumentRepositoryAsyncProxyTest method shouldDeleteByNameCallBack.

@Test
public void shouldDeleteByNameCallBack() {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    Consumer<Void> voidConsumer = v -> {
    };
    personRepository.deleteByName("name", voidConsumer);
    verify(template).delete(captor.capture(), consumerCaptor.capture());
    DocumentDeleteQuery query = captor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals(Document.of("name", "name"), condition.getDocument());
    assertEquals(voidConsumer, consumerCaptor.getValue());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) Matchers(org.mockito.Matchers) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Reflections(org.jnosql.artemis.reflection.Reflections) Condition(org.jnosql.diana.api.Condition) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Sort(org.jnosql.diana.api.Sort) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) 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) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Consumer(java.util.function.Consumer) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

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