Search in sources :

Example 1 with DocumentPreparedStatement

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

the class DefaultDocumentQueryParserTest method shouldReturnEmptySingleResult.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    Mockito.when(manager.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.empty());
    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());
    assertFalse(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 2 with DocumentPreparedStatement

use of jakarta.nosql.document.DocumentPreparedStatement 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 3 with DocumentPreparedStatement

use of jakarta.nosql.document.DocumentPreparedStatement 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 4 with DocumentPreparedStatement

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

the class InsertQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = @name)" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
    DocumentPreparedStatement prepare = parser.prepare(query, manager, observer);
    prepare.bind("name", "Diana");
    prepare.getResult();
    Mockito.verify(manager).insert(captor.capture());
    DocumentEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Document.of("name", "Diana"), entity.find("name").get());
}
Also used : DocumentEntity(jakarta.nosql.document.DocumentEntity) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with DocumentPreparedStatement

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

the class InsertQueryParserTest method shouldReturnErrorWhenDoesNotBindBeforeExecuteQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = @name)" })
public void shouldReturnErrorWhenDoesNotBindBeforeExecuteQuery(String query) {
    DocumentPreparedStatement prepare = parser.prepare(query, manager, observer);
    assertThrows(QueryException.class, prepare::getResult);
}
Also used : DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 ValueSource (org.junit.jupiter.params.provider.ValueSource)15 Document (jakarta.nosql.document.Document)6 DocumentCondition (jakarta.nosql.document.DocumentCondition)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentQuery (jakarta.nosql.document.DocumentQuery)5 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)2