|
|
|
@ -15,6 +15,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.data.mongodb.repository; |
|
|
|
package org.springframework.data.mongodb.repository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.util.Arrays.*; |
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
import static org.springframework.data.domain.Sort.Direction.*; |
|
|
|
import static org.springframework.data.domain.Sort.Direction.*; |
|
|
|
import static org.springframework.data.mongodb.core.query.Criteria.*; |
|
|
|
import static org.springframework.data.mongodb.core.query.Criteria.*; |
|
|
|
@ -66,7 +67,6 @@ import org.springframework.data.mongodb.test.util.MongoClientExtension; |
|
|
|
import org.springframework.data.mongodb.test.util.MongoTestUtils; |
|
|
|
import org.springframework.data.mongodb.test.util.MongoTestUtils; |
|
|
|
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor; |
|
|
|
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor; |
|
|
|
import org.springframework.data.repository.Repository; |
|
|
|
import org.springframework.data.repository.Repository; |
|
|
|
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider; |
|
|
|
|
|
|
|
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider; |
|
|
|
import org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider; |
|
|
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
|
|
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
|
|
|
|
|
|
|
|
|
|
|
@ -77,10 +77,12 @@ import com.mongodb.reactivestreams.client.MongoClient; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Mark Paluch |
|
|
|
* @author Mark Paluch |
|
|
|
* @author Christoph Strobl |
|
|
|
* @author Christoph Strobl |
|
|
|
|
|
|
|
* @author Jens Schauder |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ExtendWith({ MongoClientExtension.class, SpringExtension.class }) |
|
|
|
@ExtendWith({ MongoClientExtension.class, SpringExtension.class }) |
|
|
|
public class ReactiveMongoRepositoryTests { |
|
|
|
public class ReactiveMongoRepositoryTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int PERSON_COUNT = 7; |
|
|
|
static @Client MongoClient mongoClient; |
|
|
|
static @Client MongoClient mongoClient; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired ReactiveMongoTemplate template; |
|
|
|
@Autowired ReactiveMongoTemplate template; |
|
|
|
@ -154,17 +156,17 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
dave = new Person("Dave", "Matthews", 42); |
|
|
|
dave = new Person("Dave", "Matthews", 42); |
|
|
|
oliver = new Person("Oliver August", "Matthews", 4); |
|
|
|
oliver = new Person("Oliver August", "Matthews", 4); |
|
|
|
carter = new Person("Carter", "Beauford", 49); |
|
|
|
carter = new Person("Carter", "Beauford", 49); |
|
|
|
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals")); |
|
|
|
carter.setSkills(asList("Drums", "percussion", "vocals")); |
|
|
|
Thread.sleep(10); |
|
|
|
Thread.sleep(10); |
|
|
|
boyd = new Person("Boyd", "Tinsley", 45); |
|
|
|
boyd = new Person("Boyd", "Tinsley", 45); |
|
|
|
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar")); |
|
|
|
boyd.setSkills(asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar")); |
|
|
|
stefan = new Person("Stefan", "Lessard", 34); |
|
|
|
stefan = new Person("Stefan", "Lessard", 34); |
|
|
|
leroi = new Person("Leroi", "Moore", 41); |
|
|
|
leroi = new Person("Leroi", "Moore", 41); |
|
|
|
|
|
|
|
|
|
|
|
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE); |
|
|
|
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE); |
|
|
|
|
|
|
|
|
|
|
|
repository.saveAll(Arrays.asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) //
|
|
|
|
repository.saveAll(asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) //
|
|
|
|
.expectNextCount(7) //
|
|
|
|
.expectNextCount(PERSON_COUNT) //
|
|
|
|
.verifyComplete(); |
|
|
|
.verifyComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -411,7 +413,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
|
|
|
|
|
|
|
|
leroi.id = null; |
|
|
|
leroi.id = null; |
|
|
|
boyd.id = null; |
|
|
|
boyd.id = null; |
|
|
|
contactRepository.saveAll(Arrays.asList(leroi, boyd)) //
|
|
|
|
contactRepository.saveAll(asList(leroi, boyd)) //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
.expectNextCount(2) //
|
|
|
|
.expectNextCount(2) //
|
|
|
|
.verifyComplete(); |
|
|
|
.verifyComplete(); |
|
|
|
@ -430,7 +432,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
@Test // DATAMONGO-2182
|
|
|
|
@Test // DATAMONGO-2182
|
|
|
|
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() { |
|
|
|
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() { |
|
|
|
|
|
|
|
|
|
|
|
repository.findAll(person.id.in(Arrays.asList(dave.id, carter.id))) //
|
|
|
|
repository.findAll(person.id.in(asList(dave.id, carter.id))) //
|
|
|
|
.collectList() //
|
|
|
|
.collectList() //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
.assertNext(actual -> { |
|
|
|
.assertNext(actual -> { |
|
|
|
@ -468,7 +470,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
.contains(new PersonAggregate("Tinsley", "Boyd")) //
|
|
|
|
.contains(new PersonAggregate("Tinsley", "Boyd")) //
|
|
|
|
.contains(new PersonAggregate("Beauford", "Carter")) //
|
|
|
|
.contains(new PersonAggregate("Beauford", "Carter")) //
|
|
|
|
.contains(new PersonAggregate("Moore", "Leroi")) //
|
|
|
|
.contains(new PersonAggregate("Moore", "Leroi")) //
|
|
|
|
.contains(new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August"))); |
|
|
|
.contains(new PersonAggregate("Matthews", asList("Dave", "Oliver August"))); |
|
|
|
}).verifyComplete(); |
|
|
|
}).verifyComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -484,7 +486,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
new PersonAggregate("Beauford", "Carter"), //
|
|
|
|
new PersonAggregate("Beauford", "Carter"), //
|
|
|
|
new PersonAggregate("Keys", "Alicia"), //
|
|
|
|
new PersonAggregate("Keys", "Alicia"), //
|
|
|
|
new PersonAggregate("Lessard", "Stefan"), //
|
|
|
|
new PersonAggregate("Lessard", "Stefan"), //
|
|
|
|
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August")), //
|
|
|
|
new PersonAggregate("Matthews", asList("Dave", "Oliver August")), //
|
|
|
|
new PersonAggregate("Moore", "Leroi"), //
|
|
|
|
new PersonAggregate("Moore", "Leroi"), //
|
|
|
|
new PersonAggregate("Tinsley", "Boyd")); |
|
|
|
new PersonAggregate("Tinsley", "Boyd")); |
|
|
|
}) //
|
|
|
|
}) //
|
|
|
|
@ -501,7 +503,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
assertThat(actual) //
|
|
|
|
assertThat(actual) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
new PersonAggregate("Lessard", "Stefan"), //
|
|
|
|
new PersonAggregate("Lessard", "Stefan"), //
|
|
|
|
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August"))); |
|
|
|
new PersonAggregate("Matthews", asList("Dave", "Oliver August"))); |
|
|
|
}) //
|
|
|
|
}) //
|
|
|
|
.verifyComplete(); |
|
|
|
.verifyComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -576,7 +578,7 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
Person p3 = new Person(firstname, null); |
|
|
|
Person p3 = new Person(firstname, null); |
|
|
|
p3.setEmail("p3@example.com"); |
|
|
|
p3.setEmail("p3@example.com"); |
|
|
|
|
|
|
|
|
|
|
|
repository.saveAll(Arrays.asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete(); |
|
|
|
repository.saveAll(asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete(); |
|
|
|
|
|
|
|
|
|
|
|
repository.projectToLastnameAndRemoveId(firstname) //
|
|
|
|
repository.projectToLastnameAndRemoveId(firstname) //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
@ -617,6 +619,18 @@ public class ReactiveMongoRepositoryTests { |
|
|
|
.verifyComplete(); |
|
|
|
.verifyComplete(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2652
|
|
|
|
|
|
|
|
public void deleteAllById() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repository.deleteAllById(asList(carter.id, dave.id)) //
|
|
|
|
|
|
|
|
.as(StepVerifier::create) //
|
|
|
|
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repository.count().as(StepVerifier::create) //
|
|
|
|
|
|
|
|
.expectNext(PERSON_COUNT - 2L) //
|
|
|
|
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ReactivePersonRepository |
|
|
|
interface ReactivePersonRepository |
|
|
|
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> { |
|
|
|
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> { |
|
|
|
|
|
|
|
|
|
|
|
|