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));
}
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));
}
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));
}
Aggregations