DATAMONGO-2351 - Polishing.
Fix broken tests and favor StepVerifier over block() for reactive ones. Original Pull Request: #781
This commit is contained in:
@@ -231,6 +231,7 @@ interface MongoQueryExecution {
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Artyom Gabeev
|
* @author Artyom Gabeev
|
||||||
|
* @author Christoph Strobl
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -254,7 +255,7 @@ interface MongoQueryExecution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeleteResult writeResult = operations.remove(query, type, collectionName);
|
DeleteResult writeResult = operations.remove(query, type, collectionName);
|
||||||
return writeResult != null && writeResult.wasAcknowledged() ? writeResult.getDeletedCount() : 0L;
|
return writeResult.wasAcknowledged() ? writeResult.getDeletedCount() : 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ public class AbstractMongoQueryUnitTests {
|
|||||||
doReturn(executableFind).when(mongoOperationsMock).query(any());
|
doReturn(executableFind).when(mongoOperationsMock).query(any());
|
||||||
doReturn(withQueryMock).when(executableFind).as(any());
|
doReturn(withQueryMock).when(executableFind).as(any());
|
||||||
doReturn(withQueryMock).when(withQueryMock).matching(any());
|
doReturn(withQueryMock).when(withQueryMock).matching(any());
|
||||||
|
|
||||||
|
when(mongoOperationsMock.remove(any(), any(), anyString())).thenReturn(deleteResultMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-566
|
@Test // DATAMONGO-566
|
||||||
@@ -128,7 +130,7 @@ public class AbstractMongoQueryUnitTests {
|
|||||||
public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
|
public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
|
||||||
|
|
||||||
when(deleteResultMock.getDeletedCount()).thenReturn(100L);
|
when(deleteResultMock.getDeletedCount()).thenReturn(100L);
|
||||||
when(mongoOperationsMock.remove(any(), eq(Person.class), eq("persons"))).thenReturn(deleteResultMock);
|
when(deleteResultMock.wasAcknowledged()).thenReturn(true);
|
||||||
|
|
||||||
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
|
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
|
||||||
query.setDeleteQuery(true);
|
query.setDeleteQuery(true);
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
package org.springframework.data.mongodb.repository.query;
|
package org.springframework.data.mongodb.repository.query;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -174,26 +175,20 @@ public class MongoQueryExecutionUnitTests {
|
|||||||
|
|
||||||
@Test // DATAMONGO-2351
|
@Test // DATAMONGO-2351
|
||||||
public void acknowledgedDeleteReturnsDeletedCount() {
|
public void acknowledgedDeleteReturnsDeletedCount() {
|
||||||
|
|
||||||
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
||||||
.thenReturn(DeleteResult.acknowledged(10));
|
.thenReturn(DeleteResult.acknowledged(10));
|
||||||
|
|
||||||
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod);
|
assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(10L);
|
||||||
Object result = execution.execute(new Query());
|
|
||||||
|
|
||||||
assertThat(result).isEqualTo(10L);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2351
|
@Test // DATAMONGO-2351
|
||||||
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
||||||
|
|
||||||
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
||||||
.thenReturn(DeleteResult.unacknowledged());
|
.thenReturn(DeleteResult.unacknowledged());
|
||||||
|
|
||||||
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod);
|
assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(0L);
|
||||||
Object result = execution.execute(new Query());
|
|
||||||
|
|
||||||
assertThat(result).isEqualTo(0L);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PersonRepository extends Repository<Person, Long> {
|
interface PersonRepository extends Repository<Person, Long> {
|
||||||
|
|||||||
@@ -17,10 +17,14 @@ package org.springframework.data.mongodb.repository.query;
|
|||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -30,6 +34,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import org.reactivestreams.Publisher;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Range;
|
import org.springframework.data.domain.Range;
|
||||||
@@ -106,24 +111,26 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
|||||||
|
|
||||||
@Test // DATAMONGO-2351
|
@Test // DATAMONGO-2351
|
||||||
public void acknowledgedDeleteReturnsDeletedCount() {
|
public void acknowledgedDeleteReturnsDeletedCount() {
|
||||||
|
|
||||||
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
||||||
.thenReturn(Mono.just(DeleteResult.acknowledged(10)));
|
.thenReturn(Mono.just(DeleteResult.acknowledged(10)));
|
||||||
|
|
||||||
DeleteExecution execution = new DeleteExecution(operations, method);
|
Mono.from((Publisher<Long>) new DeleteExecution(operations, method).execute(new Query(), Class.class, "")) //
|
||||||
Object result = ((Mono) execution.execute(new Query(), Class.class, "")).block();
|
.as(StepVerifier::create) //
|
||||||
|
.expectNext(10L) //
|
||||||
assertThat(result).isEqualTo(10L);
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2351
|
@Test // DATAMONGO-2351
|
||||||
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
||||||
|
|
||||||
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
||||||
.thenReturn(Mono.just(DeleteResult.unacknowledged()));
|
.thenReturn(Mono.just(DeleteResult.unacknowledged()));
|
||||||
|
|
||||||
DeleteExecution execution = new DeleteExecution(operations, method);
|
Mono.from((Publisher<Long>) new DeleteExecution(operations, method).execute(new Query(), Class.class, "")) //
|
||||||
Object result = ((Mono) execution.execute(new Query(), Class.class, "")).block();
|
.as(StepVerifier::create) //
|
||||||
|
.expectNext(0L) //
|
||||||
assertThat(result).isEqualTo(0L);
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GeoRepo {
|
interface GeoRepo {
|
||||||
|
|||||||
Reference in New Issue
Block a user