use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.
the class DefaultColumnQueryParserTest method shouldReturnEmptySingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age = @age" })
public void shouldReturnEmptySingleResult(String query) {
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
Mockito.when(manager.select(Mockito.any(ColumnQuery.class))).thenReturn(Stream.empty());
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());
assertFalse(result.isPresent());
}
use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.
the class DefaultColumnQueryParserTest method shouldExecutePrepareStatement2.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age = @age" })
public void shouldExecutePrepareStatement2(String query) {
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ColumnPreparedStatement prepare = parser.prepare(query, manager, ColumnObserverParser.EMPTY);
prepare.bind("age", 12);
prepare.getResult();
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());
}
use of jakarta.nosql.column.ColumnPreparedStatement 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<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
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());
}
use of jakarta.nosql.column.ColumnPreparedStatement in project jnosql-diana by eclipse.
the class UpdateQueryParserTest method shouldExecutePrepareStatement.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = @name)" })
public void shouldExecutePrepareStatement(String query) {
ArgumentCaptor<ColumnEntity> captor = ArgumentCaptor.forClass(ColumnEntity.class);
ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
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());
}
use of jakarta.nosql.column.ColumnPreparedStatement 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) {
ColumnPreparedStatement prepare = parser.prepare(query, manager, observer);
assertThrows(QueryException.class, prepare::getResult);
}
Aggregations