Search in sources :

Example 91 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method findsPeopleByLocationWithinCircle.

// DATAMONGO-1444
@Test
void findsPeopleByLocationWithinCircle() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    repository.findByLocationWithin(new Circle(-78.99171, 45.738868, 170)).as(StepVerifier::create).expectNext(// 
    dave).verifyComplete();
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 92 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method findsPeopleGeoresultByLocationWithinBox.

// DATAMONGO-1444
@Test
void findsPeopleGeoresultByLocationWithinBox() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    repository.findByLocationNear(// 
    new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS)).as(StepVerifier::create).consumeNextWith(actual -> {
        assertThat(actual.getDistance().getValue()).isCloseTo(1, offset(1d));
        assertThat(actual.getContent()).isEqualTo(dave);
    }).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Metrics(org.springframework.data.geo.Metrics) Autowired(org.springframework.beans.factory.annotation.Autowired) ReactiveQuerydslPredicateExecutor(org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor) Document(org.springframework.data.mongodb.core.mapping.Document) ReactiveMongoOperations(org.springframework.data.mongodb.core.ReactiveMongoOperations) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Repository(org.springframework.data.repository.Repository) Assertions(org.assertj.core.api.Assertions) Update(org.springframework.data.mongodb.core.query.Update) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Sex(org.springframework.data.mongodb.repository.Person.Sex) Point(org.springframework.data.geo.Point) PageRequest(org.springframework.data.domain.PageRequest) BlockingQueue(java.util.concurrent.BlockingQueue) Client(org.springframework.data.mongodb.test.util.Client) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) ReactiveQueryMethodEvaluationContextProvider(org.springframework.data.repository.query.ReactiveQueryMethodEvaluationContextProvider) EnableIfMongoServerVersion(org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) Disposable(reactor.core.Disposable) CollectionOptions(org.springframework.data.mongodb.core.CollectionOptions) AbstractReactiveMongoConfiguration(org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException) Distance(org.springframework.data.geo.Distance) SimpleReactiveMongoRepository(org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository) UpdateDefinition(org.springframework.data.mongodb.core.query.UpdateDefinition) MongoClient(com.mongodb.reactivestreams.client.MongoClient) Direction(org.springframework.data.domain.Sort.Direction) Assertions.assertThat(org.springframework.data.mongodb.test.util.Assertions.assertThat) MongoTestUtils(org.springframework.data.mongodb.test.util.MongoTestUtils) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) ReactiveMongoRepositoryFactory(org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory) Criteria(org.springframework.data.mongodb.core.query.Criteria) Query(org.springframework.data.mongodb.core.query.Query) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) Circle(org.springframework.data.geo.Circle) BeanFactory(org.springframework.beans.factory.BeanFactory) Data(lombok.Data) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) Bean(org.springframework.context.annotation.Bean) GeoResult(org.springframework.data.geo.GeoResult) MongoClientExtension(org.springframework.data.mongodb.test.util.MongoClientExtension) NoArgsConstructor(lombok.NoArgsConstructor) Point(org.springframework.data.geo.Point) StepVerifier(reactor.test.StepVerifier) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 93 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method findsPeopleByLocationWithinBox.

// DATAMONGO-1444
@Test
void findsPeopleByLocationWithinBox() throws InterruptedException {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // Allow for index creation
    Thread.sleep(500);
    // 
    repository.findPersonByLocationNear(// 
    new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS)).as(// 
    StepVerifier::create).expectNext(// 
    dave).verifyComplete();
}
Also used : Point(org.springframework.data.geo.Point) StepVerifier(reactor.test.StepVerifier) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 94 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method shouldUseTailableCursor.

// DATAMONGO-1444
@Test
void shouldUseTailableCursor() throws Exception {
    // 
    template.dropCollection(Capped.class).then(// 
    template.createCollection(// 
    Capped.class, CollectionOptions.empty().size(1000).maxDocuments(100).capped())).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    template.insert(new Capped("value", Math.random())).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    BlockingQueue<Capped> documents = new LinkedBlockingDeque<>(100);
    Disposable disposable = cappedRepository.findByKey("value").doOnNext(documents::add).subscribe();
    assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
    template.insert(new Capped("value", Math.random())).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    assertThat(documents.poll(5, TimeUnit.SECONDS)).isNotNull();
    assertThat(documents).isEmpty();
    disposable.dispose();
}
Also used : Disposable(reactor.core.Disposable) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 95 with StepVerifier

use of reactor.test.StepVerifier in project spring-data-mongodb by spring-projects.

the class SimpleReactiveMongoRepositoryTests method setUp.

@BeforeEach
void setUp() {
    factory = new ReactiveMongoRepositoryFactory(template);
    factory.setRepositoryBaseClass(SimpleReactiveMongoRepository.class);
    factory.setBeanClassLoader(classLoader);
    factory.setBeanFactory(beanFactory);
    factory.setEvaluationContextProvider(ReactiveQueryMethodEvaluationContextProvider.DEFAULT);
    repository = factory.getRepository(ReactivePersonRepository.class);
    immutableRepository = factory.getRepository(ReactiveImmutablePersonRepository.class);
    repository.deleteAll().as(StepVerifier::create).verifyComplete();
    immutableRepository.deleteAll().as(StepVerifier::create).verifyComplete();
    dave = new ReactivePerson("Dave", "Matthews", 42);
    oliver = new ReactivePerson("Oliver August", "Matthews", 4);
    carter = new ReactivePerson("Carter", "Beauford", 49);
    boyd = new ReactivePerson("Boyd", "Tinsley", 45);
    stefan = new ReactivePerson("Stefan", "Lessard", 34);
    leroi = new ReactivePerson("Leroi", "Moore", 41);
    alicia = new ReactivePerson("Alicia", "Keys", 30);
    keith = new ImmutableReactivePerson(null, "Keith", "Urban", 53);
    james = new ImmutableReactivePerson(null, "James", "Arthur", 33);
    mariah = new ImmutableReactivePerson(null, "Mariah", "Carey", 51);
    // 
    repository.saveAll(Arrays.asList(oliver, dave, carter, boyd, stefan, leroi, alicia)).as(StepVerifier::create).expectNextCount(// 
    7).verifyComplete();
}
Also used : ReactiveMongoRepositoryFactory(org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory) StepVerifier(reactor.test.StepVerifier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StepVerifier (reactor.test.StepVerifier)234 Test (org.junit.jupiter.api.Test)176 Mono (reactor.core.publisher.Mono)111 Flux (reactor.core.publisher.Flux)92 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)77 Duration (java.time.Duration)76 BeforeEach (org.junit.jupiter.api.BeforeEach)60 Test (org.junit.Test)55 Query (org.springframework.data.mongodb.core.query.Query)54 Assertions (org.assertj.core.api.Assertions)53 Document (org.bson.Document)49 Arrays (java.util.Arrays)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Criteria (org.springframework.data.mongodb.core.query.Criteria)44 TimeUnit (java.util.concurrent.TimeUnit)42 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)42 Disposable (reactor.core.Disposable)39 List (java.util.List)38 ClassPathResource (org.springframework.core.io.ClassPathResource)38 AtomicReference (java.util.concurrent.atomic.AtomicReference)37