Search in sources :

Example 1 with NamedQueries

use of org.springframework.data.repository.core.NamedQueries in project spring-cloud-gcp by spring-cloud.

the class DatastoreQueryLookupStrategyTests method resolveSqlQueryTest.

@Test
public void resolveSqlQueryTest() {
    String queryName = "fakeNamedQueryName";
    String query = "fake query";
    when(this.queryMethod.getNamedQueryName()).thenReturn(queryName);
    Query queryAnnotation = mock(Query.class);
    when(this.queryMethod.getQueryAnnotation()).thenReturn(queryAnnotation);
    NamedQueries namedQueries = mock(NamedQueries.class);
    Parameters parameters = mock(Parameters.class);
    Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters);
    when(parameters.getNumberOfParameters()).thenReturn(1);
    when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> {
        Parameter param = mock(Parameter.class);
        when(param.getName()).thenReturn(Optional.of("tag"));
        Mockito.<Class>when(param.getType()).thenReturn(Object.class);
        return param;
    });
    when(namedQueries.hasQuery(eq(queryName))).thenReturn(true);
    when(namedQueries.getQuery(eq(queryName))).thenReturn(query);
    this.datastoreQueryLookupStrategy.resolveQuery(null, null, null, namedQueries);
    verify(this.datastoreQueryLookupStrategy, times(1)).createGqlDatastoreQuery(eq(Object.class), same(this.queryMethod), eq(query));
}
Also used : Parameters(org.springframework.data.repository.query.Parameters) Parameter(org.springframework.data.repository.query.Parameter) NamedQueries(org.springframework.data.repository.core.NamedQueries) Test(org.junit.Test)

Example 2 with NamedQueries

use of org.springframework.data.repository.core.NamedQueries in project spring-cloud-gcp by spring-cloud.

the class SpannerQueryLookupStrategyTests method resolvePartTreeQueryTest.

@Test
public void resolvePartTreeQueryTest() {
    String queryName = "fakeNamedQueryName";
    when(this.queryMethod.getNamedQueryName()).thenReturn(queryName);
    NamedQueries namedQueries = mock(NamedQueries.class);
    when(namedQueries.hasQuery(any())).thenReturn(false);
    this.spannerQueryLookupStrategy.resolveQuery(null, null, null, namedQueries);
    verify(this.spannerQueryLookupStrategy, times(1)).createPartTreeSpannerQuery(eq(Object.class), same(this.queryMethod));
}
Also used : NamedQueries(org.springframework.data.repository.core.NamedQueries) Test(org.junit.Test)

Example 3 with NamedQueries

use of org.springframework.data.repository.core.NamedQueries in project spring-cloud-gcp by spring-cloud.

the class SpannerQueryLookupStrategyTests method resolveSqlQueryTest.

@Test
public void resolveSqlQueryTest() {
    String queryName = "fakeNamedQueryName";
    String query = "fake query";
    when(this.queryMethod.getNamedQueryName()).thenReturn(queryName);
    NamedQueries namedQueries = mock(NamedQueries.class);
    Parameters parameters = mock(Parameters.class);
    // @formatter:off
    Mockito.<Parameters>when(this.queryMethod.getParameters()).thenReturn(parameters);
    // @formatter:off
    when(parameters.getNumberOfParameters()).thenReturn(1);
    when(parameters.getParameter(anyInt())).thenAnswer((invocation) -> {
        Parameter param = mock(Parameter.class);
        when(param.getName()).thenReturn(Optional.of("tag"));
        // @formatter:off
        Mockito.<Class>when(param.getType()).thenReturn(Object.class);
        // @formatter:on
        return param;
    });
    when(namedQueries.hasQuery(eq(queryName))).thenReturn(true);
    when(namedQueries.getQuery(eq(queryName))).thenReturn(query);
    this.spannerQueryLookupStrategy.resolveQuery(null, null, null, namedQueries);
    verify(this.spannerQueryLookupStrategy, times(1)).createSqlSpannerQuery(eq(Object.class), same(this.queryMethod), eq(query), eq(false));
}
Also used : Parameters(org.springframework.data.repository.query.Parameters) Parameter(org.springframework.data.repository.query.Parameter) NamedQueries(org.springframework.data.repository.core.NamedQueries) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 NamedQueries (org.springframework.data.repository.core.NamedQueries)3 Parameter (org.springframework.data.repository.query.Parameter)2 Parameters (org.springframework.data.repository.query.Parameters)2