DATACOUCH-246 - Polishing.
Removed the dynamic return type obtained from the ResultProcessor held in a query implementation field as this breaks thread safety. We now hand the type to read into the execution methods. Adapted test cases accordingly and removed a bit of mocking. Original pull request: #122.
This commit is contained in:
@@ -57,7 +57,6 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
|
||||
protected final CouchbaseQueryMethod queryMethod;
|
||||
private final CouchbaseOperations couchbaseOperations;
|
||||
private Class<?> returnedType;
|
||||
|
||||
protected AbstractN1qlBasedQuery(CouchbaseQueryMethod queryMethod, CouchbaseOperations couchbaseOperations) {
|
||||
this.queryMethod = queryMethod;
|
||||
@@ -87,11 +86,9 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
|
||||
ResultProcessor processor = this.queryMethod.getResultProcessor().withDynamicProjection(accessor);
|
||||
ReturnedType returnedType = processor.getReturnedType();
|
||||
this.returnedType = returnedType.getReturnedType();
|
||||
|
||||
if (this.returnedType.isInterface()) {
|
||||
this.returnedType = returnedType.getDomainType();
|
||||
}
|
||||
|
||||
Class<?> typeToRead = returnedType.getTypeToRead();
|
||||
typeToRead = typeToRead == null ? returnedType.getDomainType() : typeToRead;
|
||||
|
||||
Statement statement = getStatement(accessor, parameters, returnedType);
|
||||
JsonValue queryPlaceholderValues = getPlaceholderValues(accessor);
|
||||
@@ -104,8 +101,7 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
Statement countStatement = getCount(accessor, parameters);
|
||||
N1qlQuery countQuery = buildQuery(countStatement, queryPlaceholderValues,
|
||||
getCouchbaseOperations().getDefaultConsistency().n1qlConsistency());
|
||||
return processor.processResult(executeDependingOnType(query, countQuery, queryMethod, accessor.getPageable(),
|
||||
queryMethod.isPageQuery(), queryMethod.isSliceQuery(), queryMethod.isModifyingQuery()));
|
||||
return processor.processResult(executeDependingOnType(query, countQuery, queryMethod, accessor.getPageable(), typeToRead));
|
||||
}
|
||||
|
||||
protected static N1qlQuery buildQuery(Statement statement, JsonValue queryPlaceholderValues, ScanConsistency scanConsistency) {
|
||||
@@ -122,22 +118,23 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
return query;
|
||||
}
|
||||
|
||||
protected Object executeDependingOnType(N1qlQuery query, N1qlQuery countQuery, QueryMethod queryMethod, Pageable pageable,
|
||||
boolean isPage, boolean isSlice, boolean isModifying) {
|
||||
if (isModifying) {
|
||||
protected Object executeDependingOnType(N1qlQuery query, N1qlQuery countQuery, QueryMethod queryMethod,
|
||||
Pageable pageable, Class<?> typeToRead) {
|
||||
|
||||
if (queryMethod.isModifyingQuery()) {
|
||||
throw new UnsupportedOperationException("Modifying queries not yet supported");
|
||||
}
|
||||
|
||||
if (isPage) {
|
||||
return executePaged(query, countQuery, pageable);
|
||||
} else if (isSlice) {
|
||||
return executeSliced(query, countQuery, pageable);
|
||||
if (queryMethod.isPageQuery()) {
|
||||
return executePaged(query, countQuery, pageable, typeToRead);
|
||||
} else if (queryMethod.isSliceQuery()) {
|
||||
return executeSliced(query, countQuery, pageable, typeToRead);
|
||||
} else if (queryMethod.isCollectionQuery()) {
|
||||
return executeCollection(query);
|
||||
} else if (queryMethod.isQueryForEntity()) {
|
||||
return executeEntity(query);
|
||||
return executeCollection(query, typeToRead);
|
||||
} else if (queryMethod.isStreamQuery()){
|
||||
return executeStream(query);
|
||||
return executeStream(query, typeToRead);
|
||||
} else if (queryMethod.isQueryForEntity()) {
|
||||
return executeEntity(query, typeToRead);
|
||||
} else if (queryMethod.getReturnedObjectType().isPrimitive()
|
||||
&& useGeneratedCountQuery()) {
|
||||
//attempt to execute the created COUNT query
|
||||
@@ -156,24 +153,24 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<?> executeCollection(N1qlQuery query) {
|
||||
protected List<?> executeCollection(N1qlQuery query, Class<?> typeToRead) {
|
||||
logIfNecessary(query);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, this.returnedType);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, typeToRead);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Object executeEntity(N1qlQuery query) {
|
||||
protected Object executeEntity(N1qlQuery query, Class<?> typeToRead) {
|
||||
logIfNecessary(query);
|
||||
List<?> result = executeCollection(query);
|
||||
List<?> result = executeCollection(query, typeToRead);
|
||||
return result.isEmpty() ? null : result.get(0);
|
||||
}
|
||||
|
||||
protected Object executeStream(N1qlQuery query) {
|
||||
protected Object executeStream(N1qlQuery query, Class<?> typeToRead) {
|
||||
logIfNecessary(query);
|
||||
return StreamUtils.createStreamFromIterator(executeCollection(query).iterator());
|
||||
return StreamUtils.createStreamFromIterator(executeCollection(query, typeToRead).iterator());
|
||||
}
|
||||
|
||||
protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable) {
|
||||
protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) {
|
||||
Assert.notNull(pageable);
|
||||
long total = 0L;
|
||||
logIfNecessary(countQuery);
|
||||
@@ -183,14 +180,14 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery {
|
||||
}
|
||||
|
||||
logIfNecessary(query);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, this.returnedType);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, typeToRead);
|
||||
return new PageImpl(result, pageable, total);
|
||||
}
|
||||
|
||||
protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable) {
|
||||
protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class<?> typeToRead) {
|
||||
Assert.notNull(pageable);
|
||||
logIfNecessary(query);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, this.returnedType);
|
||||
List<?> result = couchbaseOperations.findByN1QL(query, typeToRead);
|
||||
int pageSize = pageable.getPageSize();
|
||||
boolean hasNext = result.size() > pageSize;
|
||||
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.couchbase.repository.query;
|
||||
|
||||
import static com.couchbase.client.java.query.Select.select;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.couchbase.client.java.document.json.JsonArray;
|
||||
import com.couchbase.client.java.document.json.JsonObject;
|
||||
@@ -18,13 +36,29 @@ import com.couchbase.client.java.query.Statement;
|
||||
import com.couchbase.client.java.query.consistency.ScanConsistency;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.data.couchbase.core.mapping.event.User;
|
||||
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.query.QueryCreationException;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
import org.springframework.data.repository.query.QueryMethod;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractN1qlBasedQuery}.
|
||||
*
|
||||
* @author Simon Basle
|
||||
* @author Subhashni Balakrishnan
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class AbstractN1qlBasedQueryTest {
|
||||
|
||||
CouchbaseMappingContext context = new CouchbaseMappingContext();
|
||||
ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(SampleRepository.class);
|
||||
|
||||
@Test
|
||||
public void testEmptyArgumentsShouldProduceSimpleN1qlQuery() throws Exception {
|
||||
@@ -77,162 +111,201 @@ public class AbstractN1qlBasedQueryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChooseCollectionExecutionWhenCollectionType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldChooseCollectionExecutionWhenCollectionType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("findAll");
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class), any(Class.class)))
|
||||
.thenCallRealMethod();
|
||||
when(queryMethod.isCollectionQuery()).thenReturn(true);
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, false);
|
||||
verify(mock).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Object.class);
|
||||
verify(mock).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChooseEntityExecutionWhenEntityType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldChooseEntityExecutionWhenEntityType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("findById", Integer.class);
|
||||
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class), any(Class.class)))
|
||||
.thenCallRealMethod();
|
||||
when(queryMethod.isQueryForEntity()).thenReturn(true);
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChooseStreamExecutionWhenStreamType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldChooseStreamExecutionWhenStreamType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("streamAll");
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
any(Class.class)))
|
||||
.thenCallRealMethod();
|
||||
when(queryMethod.isStreamQuery()).thenReturn(true);
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChoosePagedExecutionWhenPageType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldChoosePagedExecutionWhenPageType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("findAllPaged", Pageable.class);
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
any(Class.class)))
|
||||
.thenCallRealMethod();
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, true, false, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChooseSlicedExecutionWhenSliceType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldChooseSlicedExecutionWhenSliceType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("findAllSliced", Pageable.class);
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
.thenCallRealMethod();
|
||||
when(queryMethod.isSliceQuery()).thenReturn(true);
|
||||
any(Class.class))).thenCallRealMethod();
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, true, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowWhenModifyingType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
public void shouldThrowWhenModifyingType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("modifyingMethod");
|
||||
CouchbaseQueryMethod queryMethod = spy(new CouchbaseQueryMethod(method, metadata, projectionFactory, context));
|
||||
when(queryMethod.isModifyingQuery()).thenReturn(true);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
.thenCallRealMethod();
|
||||
any(Class.class))).thenCallRealMethod();
|
||||
|
||||
try { mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, true); fail(); } catch (UnsupportedOperationException e) { }
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
try { mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class); fail(); } catch (UnsupportedOperationException e) { }
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteSingleProjectionWhenRandomObjectReturnType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
doReturn(CountDownLatch.class).when(queryMethod).getReturnedObjectType();
|
||||
public void shouldExecuteSingleProjectionWhenRandomObjectReturnType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("countDown");
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
.thenCallRealMethod();
|
||||
any(Class.class))).thenCallRealMethod();
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteSingleProjectionWhenPrimitiveReturnType() {
|
||||
CouchbaseQueryMethod queryMethod = Mockito.mock(CouchbaseQueryMethod.class);
|
||||
doReturn(long.class).when(queryMethod).getReturnedObjectType();
|
||||
public void shouldExecuteSingleProjectionWhenPrimitiveReturnType() throws Exception {
|
||||
|
||||
Method method = SampleRepository.class.getMethod("longMethod");
|
||||
CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method, metadata, projectionFactory, context);
|
||||
|
||||
N1qlQuery query = Mockito.mock(N1qlQuery.class);
|
||||
Pageable pageable = Mockito.mock(Pageable.class);
|
||||
AbstractN1qlBasedQuery mock = mock(AbstractN1qlBasedQuery.class);
|
||||
when(mock.executeDependingOnType(any(N1qlQuery.class), any(N1qlQuery.class), any(QueryMethod.class), any(Pageable.class),
|
||||
anyBoolean(), anyBoolean(), anyBoolean()))
|
||||
.thenCallRealMethod();
|
||||
any(Class.class))).thenCallRealMethod();
|
||||
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, false, false, false);
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class));
|
||||
mock.executeDependingOnType(query, query, queryMethod, pageable, Sample.class);
|
||||
|
||||
verify(mock, never()).executeCollection(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeEntity(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executeStream(any(N1qlQuery.class), any(Class.class));
|
||||
verify(mock, never()).executePaged(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock, never()).executeSliced(any(N1qlQuery.class), any(N1qlQuery.class), any(Pageable.class), any(Class.class));
|
||||
verify(mock).executeSingleProjection(any(N1qlQuery.class));
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
Integer id;
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<Sample, Integer> {
|
||||
|
||||
Collection<Sample> findAll();
|
||||
|
||||
Sample findById(Integer id);
|
||||
|
||||
Stream<Sample> streamAll();
|
||||
|
||||
Page<Sample> findAllPaged(Pageable pageable);
|
||||
|
||||
Slice<Sample> findAllSliced(Pageable pageable);
|
||||
|
||||
void modifyingMethod();
|
||||
|
||||
CountDownLatch countDown();
|
||||
|
||||
long longMethod();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user