Search in sources :

Example 6 with ColumnPreparedStatement

use of jakarta.nosql.column.ColumnPreparedStatement 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) {
    ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
    assertThrows(QueryException.class, prepare::getResult);
}
Also used : ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ColumnPreparedStatement

use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.

the class DefaultColumnQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age = @age" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
    ColumnPreparedStatement prepare = parser.prepare(query, manager, ColumnObserverParser.EMPTY);
    prepare.bind("age", 12);
    prepare.getResult();
    Mockito.verify(manager).delete(captor.capture());
    ColumnDeleteQuery columnDeleteQuery = captor.getValue();
    ColumnCondition columnCondition = columnDeleteQuery.getCondition().get();
    Column column = columnCondition.getColumn();
    assertEquals(Condition.EQUALS, columnCondition.getCondition());
    assertEquals("age", column.getName());
    assertEquals(12, column.get());
}
Also used : ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) Column(jakarta.nosql.column.Column) ColumnCondition(jakarta.nosql.column.ColumnCondition) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ColumnPreparedStatement

use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.

the class DefaultColumnQueryParserTest method shouldExecutePrepareStatement1.

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

Example 9 with ColumnPreparedStatement

use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.

the class DefaultColumnQueryParserTest method shouldSingleResult.

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

Example 10 with ColumnPreparedStatement

use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.

the class DefaultColumnQueryParserTest method shouldExecutePrepareStatement3.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = @name)" })
public void shouldExecutePrepareStatement3(String query) {
    ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
    ColumnPreparedStatement prepare = parser.prepare(query, manager, ColumnObserverParser.EMPTY);
    prepare.bind("name", "Diana");
    prepare.getResult();
    Mockito.verify(manager).update(captor.capture());
    ColumnEntity entity = captor.getValue();
    assertEquals("God", entity.getName());
    assertEquals(Column.of("name", "Diana"), entity.find("name").get());
}
Also used : ColumnEntity(jakarta.nosql.column.ColumnEntity) ColumnPreparedStatement(jakarta.nosql.column.ColumnPreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 ValueSource (org.junit.jupiter.params.provider.ValueSource)15 Column (jakarta.nosql.column.Column)6 ColumnCondition (jakarta.nosql.column.ColumnCondition)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)6 ColumnQuery (jakarta.nosql.column.ColumnQuery)5 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)2