|
|
|
|
@ -15,7 +15,8 @@
@@ -15,7 +15,8 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.springframework.data.mongodb.repository.query; |
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
|
import static org.mockito.ArgumentMatchers.*; |
|
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
@ -46,6 +47,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@@ -46,6 +47,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
|
|
|
|
import org.springframework.data.mongodb.core.query.NearQuery; |
|
|
|
|
import org.springframework.data.mongodb.core.query.Query; |
|
|
|
|
import org.springframework.data.mongodb.repository.Person; |
|
|
|
|
import org.springframework.data.mongodb.repository.query.MongoQueryExecution.DeleteExecution; |
|
|
|
|
import org.springframework.data.mongodb.repository.query.MongoQueryExecution.PagedExecution; |
|
|
|
|
import org.springframework.data.mongodb.repository.query.MongoQueryExecution.PagingGeoNearExecution; |
|
|
|
|
import org.springframework.data.projection.ProjectionFactory; |
|
|
|
|
@ -55,11 +57,14 @@ import org.springframework.data.repository.core.RepositoryMetadata;
@@ -55,11 +57,14 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
|
|
|
|
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; |
|
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
import com.mongodb.client.result.DeleteResult; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unit tests for {@link MongoQueryExecution}. |
|
|
|
|
* |
|
|
|
|
* @author Mark Paluch |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
* @author Artyom Gabeev |
|
|
|
|
* @soundtrack U Can't Touch This - MC Hammer |
|
|
|
|
*/ |
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
|
@ -167,6 +172,30 @@ public class MongoQueryExecutionUnitTests {
@@ -167,6 +172,30 @@ public class MongoQueryExecutionUnitTests {
|
|
|
|
|
verify(terminatingMock).count(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2351
|
|
|
|
|
public void acknowledgedDeleteReturnsDeletedCount() { |
|
|
|
|
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString())) |
|
|
|
|
.thenReturn(DeleteResult.acknowledged(10)); |
|
|
|
|
|
|
|
|
|
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod); |
|
|
|
|
Object result = execution.execute(new Query()); |
|
|
|
|
|
|
|
|
|
assertThat(result).isEqualTo(10L); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2351
|
|
|
|
|
public void unacknowledgedDeleteReturnsZeroDeletedCount() { |
|
|
|
|
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString())) |
|
|
|
|
.thenReturn(DeleteResult.unacknowledged()); |
|
|
|
|
|
|
|
|
|
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod); |
|
|
|
|
Object result = execution.execute(new Query()); |
|
|
|
|
|
|
|
|
|
assertThat(result).isEqualTo(0L); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface PersonRepository extends Repository<Person, Long> { |
|
|
|
|
|
|
|
|
|
GeoPage<Person> findByLocationNear(Point point, Distance distance, Pageable pageable); |
|
|
|
|
|