use of jakarta.nosql.document.DocumentPreparedStatement 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<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
DocumentPreparedStatement prepare = parser.prepare(query, manager, observer);
prepare.bind("name", "Diana");
prepare.getResult();
Mockito.verify(manager).update(captor.capture());
DocumentEntity entity = captor.getValue();
assertEquals("God", entity.getName());
assertEquals(Document.of("name", "Diana"), entity.find("name").get());
}
use of jakarta.nosql.document.DocumentPreparedStatement in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldReturnErrorSingleResult.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where age = @age" })
public void shouldReturnErrorSingleResult(String query) {
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
Mockito.when(manager.select(Mockito.any(DocumentQuery.class))).thenReturn(Stream.of(mock(DocumentEntity.class), mock(DocumentEntity.class)));
DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
prepare.bind("age", 12);
assertThrows(NonUniqueResultException.class, () -> prepare.getSingleResult());
}
use of jakarta.nosql.document.DocumentPreparedStatement in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldExecutePrepareStatement1.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "insert God (name = @name)" })
public void shouldExecutePrepareStatement1(String query) {
ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
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());
}
use of jakarta.nosql.document.DocumentPreparedStatement in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest 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, manager, DocumentObserverParser.EMPTY);
prepare.bind("age", 12);
prepare.getResult();
Mockito.verify(manager).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());
}
use of jakarta.nosql.document.DocumentPreparedStatement in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldExecutePrepareStatement3.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "update God (name = @name)" })
public void shouldExecutePrepareStatement3(String query) {
ArgumentCaptor<DocumentEntity> captor = ArgumentCaptor.forClass(DocumentEntity.class);
DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
prepare.bind("name", "Diana");
prepare.getResult();
Mockito.verify(manager).update(captor.capture());
DocumentEntity entity = captor.getValue();
assertEquals("God", entity.getName());
assertEquals(Document.of("name", "Diana"), entity.find("name").get());
}
Aggregations