Search in sources :

Example 16 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameEq.

@Test
public void shouldSelectWhereNameEq() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").eq(name).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.EQUALS, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals(name, document.get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 17 with Document

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameLt.

@Test
public void shouldSelectWhereNameLt() {
    String documentCollection = "documentCollection";
    Number value = 10;
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").lt(value).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.LESSER_THAN, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals(value, document.get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 18 with Document

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

the class DefaultDocumentQueryParserTest method shouldExecutePrepareStatement2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldExecutePrepareStatement2(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
    prepare.bind("age", 12);
    prepare.getResult();
    Mockito.verify(manager).select(captor.capture());
    DocumentQuery documentQuery = captor.getValue();
    DocumentCondition documentCondition = documentQuery.getCondition().get();
    Document document = documentCondition.getDocument();
    assertEquals(Condition.EQUALS, documentCondition.getCondition());
    assertEquals("age", document.getName());
    assertEquals(12, document.get());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with Document

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

the class DefaultDocumentQueryParserTest method shouldSingleResult.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldSingleResult(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    Mockito.when(manager.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.of(mock(DocumentEntity.class)));
    DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
    prepare.bind("age", 12);
    final Optional<DocumentEntity> result = prepare.getSingleResult();
    Mockito.verify(manager).select(captor.capture());
    DocumentQuery columnQuery = captor.getValue();
    DocumentCondition columnCondition = columnQuery.getCondition().get();
    Document column = columnCondition.getDocument();
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("age", column.getName());
    assertEquals(12, column.get());
    assertTrue(result.isPresent());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with Document

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

the class DefaultDocumentCondition method or.

static DefaultDocumentCondition or(DocumentCondition... conditions) {
    requireNonNull(conditions, "condition is required");
    Document document = Document.of(Condition.OR.getNameField(), asList(conditions));
    return DefaultDocumentCondition.of(document, Condition.OR);
}
Also used : Document(jakarta.nosql.document.Document)

Aggregations

Document (jakarta.nosql.document.Document)196 Test (org.junit.jupiter.api.Test)140 DocumentEntity (jakarta.nosql.document.DocumentEntity)115 DocumentQuery (jakarta.nosql.document.DocumentQuery)93 DocumentCondition (jakarta.nosql.document.DocumentCondition)60 List (java.util.List)60 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)44 Arrays.asList (java.util.Arrays.asList)33 ArrayList (java.util.ArrayList)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 ValueSource (org.junit.jupiter.params.provider.ValueSource)26 TypeReference (jakarta.nosql.TypeReference)21 HashMap (java.util.HashMap)20 Map (java.util.Map)17 Collectors (java.util.stream.Collectors)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)14 Matchers.contains (org.hamcrest.Matchers.contains)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14