Search in sources :

Example 11 with DocumentPreparedStatement

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

the class UpdateQueryParserTest method shouldReturnErrorWhenDoesNotBindBeforeExecuteQuery.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update 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)

Example 12 with DocumentPreparedStatement

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

the class DeleteQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age = @age" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    DocumentPreparedStatement prepare = parser.prepare(query, documentCollection, observer);
    prepare.bind("age", 12);
    prepare.getResult();
    Mockito.verify(documentCollection).delete(captor.capture());
    DocumentDeleteQuery 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 : DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with DocumentPreparedStatement

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

the class DeleteQueryParserTest method shouldReturnErrorWhenDontBindParameters.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age = @age" })
public void shouldReturnErrorWhenDontBindParameters(String query) {
    DocumentPreparedStatement prepare = parser.prepare(query, documentCollection, 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)

Example 14 with DocumentPreparedStatement

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

the class SelectQueryParserTest method shouldReturnErrorWhenDontBindParameters.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldReturnErrorWhenDontBindParameters(String query) {
    DocumentPreparedStatement prepare = parser.prepare(query, documentCollection, 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)

Example 15 with DocumentPreparedStatement

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

the class SelectQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where age = @age" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    DocumentPreparedStatement prepare = parser.prepare(query, documentCollection, observer);
    prepare.bind("age", 12);
    prepare.getResult();
    Mockito.verify(documentCollection).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)

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