Search in sources :

Example 16 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class KeyValueRepositoryProxyTest method shouldFindByQueryWithParameter.

@Test
public void shouldFindByQueryWithParameter() {
    PreparedStatement prepare = Mockito.mock(PreparedStatement.class);
    when(template.prepare("get @id", User.class)).thenReturn(prepare);
    userRepository.findByQuery("id");
    verify(template).prepare("get @id", User.class);
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 17 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnNull.

@Test
public void shouldReturnNull() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Method method = getMethod(PersonRepository.class, "getInstance");
    Function<String, Stream<?>> stream = q -> Stream.empty();
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withPrepareConverter(s -> preparedStatement).build();
    Object execute = dynamicReturn.execute();
    Assertions.assertNull(execute);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 18 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DynamicQueryMethodReturnTest method shouldReturnFromPrepareStatement.

@Test
public void shouldReturnFromPrepareStatement() throws NoSuchMethodException {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    Mockito.when(preparedStatement.<Person>getResult()).thenReturn(Stream.of(new Person("Ada")));
    Method method = getMethod(PersonRepository.class, "query");
    Function<String, Stream<?>> stream = q -> Stream.of(new Person("Ada"));
    DynamicQueryMethodReturn dynamicReturn = DynamicQueryMethodReturn.builder().withTypeClass(Person.class).withMethod(method).withQueryConverter(stream).withArgs(new Object[] { "Ada" }).withPrepareConverter(s -> preparedStatement).build();
    Object execute = dynamicReturn.execute();
    Assertions.assertTrue(execute instanceof Iterable);
    Iterable<Person> persons = (List) execute;
    Assertions.assertEquals(new Person("Ada"), persons.iterator().next());
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Collection(java.util.Collection) Set(java.util.Set) Function(java.util.function.Function) Query(jakarta.nosql.mapping.Query) Repository(jakarta.nosql.mapping.Repository) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Queue(java.util.Queue) Method(java.lang.reflect.Method) Param(jakarta.nosql.mapping.Param) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Stream(java.util.stream.Stream) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 19 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class DefaultDocumentTemplateTest method shouldPreparedStatement.

@Test
public void shouldPreparedStatement() {
    PreparedStatement preparedStatement = subject.prepare("select * from Person where name = @name");
    preparedStatement.bind("name", "Ada");
    preparedStatement.getResult();
    ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(managerMock).select(queryCaptor.capture());
    DocumentQuery query = queryCaptor.getValue();
    assertEquals("Person", query.getDocumentCollection());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 20 with PreparedStatement

use of jakarta.nosql.mapping.PreparedStatement in project jnosql-diana by eclipse.

the class AbstractGraphTemplateTest method shouldExecutePrepareStatementWithErrorWhenThereIsMoreThanOneResult.

@Test
public void shouldExecutePrepareStatementWithErrorWhenThereIsMoreThanOneResult() {
    getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
    getGraphTemplate().insert(Person.builder().withAge().withName("Poliana").build());
    PreparedStatement prepare = getGraphTemplate().prepare("g.V().hasLabel(param)");
    prepare.bind("param", "Person");
    assertThrows(NonUniqueResultException.class, prepare::getSingleResult);
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Aggregations

PreparedStatement (jakarta.nosql.mapping.PreparedStatement)25 Test (org.junit.jupiter.api.Test)25 List (java.util.List)13 NonUniqueResultException (jakarta.nosql.NonUniqueResultException)11 Param (jakarta.nosql.mapping.Param)11 Query (jakarta.nosql.mapping.Query)11 Repository (jakarta.nosql.mapping.Repository)11 Method (java.lang.reflect.Method)11 Collection (java.util.Collection)11 Objects (java.util.Objects)11 Optional (java.util.Optional)11 Queue (java.util.Queue)11 Set (java.util.Set)11 Function (java.util.function.Function)11 Stream (java.util.stream.Stream)11 Assertions (org.junit.jupiter.api.Assertions)11 Mockito (org.mockito.Mockito)11 Person (org.eclipse.jnosql.mapping.graph.model.Person)3 Person (jakarta.nosql.tck.entities.Person)2 Arrays.asList (java.util.Arrays.asList)2