Search in sources :

Example 1 with CaseFirst

use of org.springframework.data.mongodb.core.query.Collation.CaseFirst in project spring-data-mongodb by spring-projects.

the class DefaultReactiveIndexOperationsTests method shouldCreateIndexWithCollationCorrectly.

// DATAMONGO-1518
@Test
public void shouldCreateIndexWithCollationCorrectly() {
    IndexDefinition id = new Index().named("with-collation").on("xyz", Direction.ASC).collation(Collation.of("de_AT").caseFirst(CaseFirst.off()));
    indexOps.ensureIndex(id).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    Document expected = // 
    new Document("locale", "de_AT").append("caseLevel", // 
    false).append("caseFirst", // 
    "off").append("strength", // 
    3).append("numericOrdering", // 
    false).append("alternate", // 
    "non-ignorable").append("maxVariable", // 
    "punct").append("normalization", // 
    false).append("backwards", false);
    // 
    indexOps.getIndexInfo().filter(this.indexByName("with-collation")).as(StepVerifier::create).consumeNextWith(indexInfo -> {
        assertThat(indexInfo.getCollation()).isPresent();
        // version is set by MongoDB server - we remove it to avoid errors when upgrading server version.
        Document result = indexInfo.getCollation().get();
        result.remove("version");
        assertThat(result).isEqualTo(expected);
    }).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) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Aggregations

MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)1 Predicate (java.util.function.Predicate)1 Assertions (org.assertj.core.api.Assertions)1 Document (org.bson.Document)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Direction (org.springframework.data.domain.Sort.Direction)1 QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)1 Index (org.springframework.data.mongodb.core.index.Index)1 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)1 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)1 PartialIndexFilter (org.springframework.data.mongodb.core.index.PartialIndexFilter)1 Field (org.springframework.data.mongodb.core.mapping.Field)1 Collation (org.springframework.data.mongodb.core.query.Collation)1 CaseFirst (org.springframework.data.mongodb.core.query.Collation.CaseFirst)1 Criteria (org.springframework.data.mongodb.core.query.Criteria)1 MongoTemplateExtension (org.springframework.data.mongodb.test.util.MongoTemplateExtension)1 ReactiveMongoTestTemplate (org.springframework.data.mongodb.test.util.ReactiveMongoTestTemplate)1 Template (org.springframework.data.mongodb.test.util.Template)1