Search in sources :

Example 41 with StepVerifier

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

the class DefaultReactiveIndexOperationsTests method shouldApplyPartialFilterWithMappedPropertyCorrectly.

// DATAMONGO-1682, DATAMONGO-2198
@Test
public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
    IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC).partial(of(where("quantity").gte(10)));
    indexOps.ensureIndex(id).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    indexOps.getIndexInfo().filter(this.indexByName("partial-with-mapped-criteria")).as(StepVerifier::create).consumeNextWith(indexInfo -> {
        assertThat(Document.parse(indexInfo.getPartialFilterExpression())).isEqualTo(Document.parse("{ \"qty\" : { \"$gte\" : 10 } }"));
    }).verifyComplete();
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) ReactiveMongoTestTemplate(org.springframework.data.mongodb.test.util.ReactiveMongoTestTemplate) Collation(org.springframework.data.mongodb.core.query.Collation) Template(org.springframework.data.mongodb.test.util.Template) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) Assertions(org.assertj.core.api.Assertions) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) MongoTemplateExtension(org.springframework.data.mongodb.test.util.MongoTemplateExtension) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 42 with StepVerifier

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

the class DefaultReactiveIndexOperationsTests method shouldApplyPartialFilterCorrectly.

// DATAMONGO-1682, DATAMONGO-2198
@Test
public void shouldApplyPartialFilterCorrectly() {
    IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC).partial(of(where("q-t-y").gte(10)));
    indexOps.ensureIndex(id).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    indexOps.getIndexInfo().filter(this.indexByName("partial-with-criteria")).as(StepVerifier::create).consumeNextWith(indexInfo -> {
        assertThat(Document.parse(indexInfo.getPartialFilterExpression())).isEqualTo(Document.parse("{ \"q-t-y\" : { \"$gte\" : 10 } }"));
    }).verifyComplete();
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) ReactiveMongoTestTemplate(org.springframework.data.mongodb.test.util.ReactiveMongoTestTemplate) Collation(org.springframework.data.mongodb.core.query.Collation) Template(org.springframework.data.mongodb.test.util.Template) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) Assertions(org.assertj.core.api.Assertions) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) MongoTemplateExtension(org.springframework.data.mongodb.test.util.MongoTemplateExtension) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 43 with StepVerifier

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

the class DefaultReactiveIndexOperationsTests method shouldFavorExplicitMappingHintViaClass.

// DATAMONGO-1682, DATAMONGO-2198
@Test
public void shouldFavorExplicitMappingHintViaClass() {
    IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC).partial(of(where("age").gte(10)));
    indexOps = new DefaultReactiveIndexOperations(template, this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
    indexOps.ensureIndex(id).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    indexOps.getIndexInfo().filter(this.indexByName("partial-with-inheritance")).as(StepVerifier::create).consumeNextWith(indexInfo -> {
        assertThat(Document.parse(indexInfo.getPartialFilterExpression())).isEqualTo(Document.parse("{ \"a_g_e\" : { \"$gte\" : 10 } }"));
    }).verifyComplete();
}
Also used : Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) ReactiveMongoTestTemplate(org.springframework.data.mongodb.test.util.ReactiveMongoTestTemplate) Collation(org.springframework.data.mongodb.core.query.Collation) Template(org.springframework.data.mongodb.test.util.Template) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) Assertions(org.assertj.core.api.Assertions) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) MongoTemplateExtension(org.springframework.data.mongodb.test.util.MongoTemplateExtension) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 44 with StepVerifier

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

the class ReactiveFindOperationSupportTests method existsShouldReturnFalseIfNoElementExistsInCollection.

// DATAMONGO-1719
@Test
void existsShouldReturnFalseIfNoElementExistsInCollection() {
    blocking.remove(new BasicQuery("{}"), STAR_WARS);
    template.query(Person.class).exists().as(StepVerifier::create).expectNext(false).verifyComplete();
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 45 with StepVerifier

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

the class ReactiveFindOperationSupportTests method distinctReturnsSimpleFieldValuesCorrectly.

// DATAMONGO-1761
@Test
void distinctReturnsSimpleFieldValuesCorrectly() {
    Person anakin = new Person();
    anakin.firstname = "anakin";
    anakin.ability = "dark-lord";
    Person padme = new Person();
    padme.firstname = "padme";
    padme.ability = 42L;
    Person jaja = new Person();
    jaja.firstname = "jaja";
    jaja.ability = new Date();
    blocking.save(anakin);
    blocking.save(padme);
    blocking.save(jaja);
    Consumer<Object> containedInAbilities = in(anakin.ability, padme.ability, jaja.ability);
    // 
    template.query(Person.class).distinct("ability").all().as(StepVerifier::create).assertNext(// 
    containedInAbilities).assertNext(// 
    containedInAbilities).assertNext(// 
    containedInAbilities).verifyComplete();
}
Also used : StepVerifier(reactor.test.StepVerifier) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

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